isl_printer: add NULL checks
[isl.git] / doc / user.pod
blobabeaa360d71391c0169af214630c94f5ed1d4bf6
1 =head1 Introduction
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
8 using C<GMP>.
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>.
23 =head2 Backward Incompatible Changes
25 =head3 Changes since isl-0.02
27 =over
29 =item * The old printing functions have been deprecated
30 and replaced by C<isl_printer> functions, see L<Input and Output>.
32 =item * Most functions related to dependence analysis have acquired
33 an extra C<must> argument.  To obtain the old behavior, this argument
34 should be given the value 1.  See L<Dependence Analysis>.
36 =back
38 =head1 Installation
40 The source of C<isl> can be obtained either as a tarball
41 or from the git repository.  Both are available from
42 L<http://freshmeat.net/projects/isl/>.
43 The installation process depends on how you obtained
44 the source.
46 =head2 Installation from the git repository
48 =over
50 =item 1 Clone or update the repository
52 The first time the source is obtained, you need to clone
53 the repository.
55         git clone git://repo.or.cz/isl.git
57 To obtain updates, you need to pull in the latest changes
59         git pull
61 =item 2 Get submodule (optional)
63 C<isl> can optionally use the C<piplib> library and provides
64 this library as a submodule.  If you want to use it, then
65 after you have cloned C<isl>, you need to grab the submodules
67         git submodule init
68         git submodule update
70 To obtain updates, you only need
72         git submodule update
74 Note that C<isl> currently does not use any C<piplib>
75 functionality by default.
77 =item 3 Generate C<configure>
79         ./autogen.sh
81 =back
83 After performing the above steps, continue
84 with the L<Common installation instructions>.
86 =head2 Common installation instructions
88 =over
90 =item 1 Obtain C<GMP>
92 Building C<isl> requires C<GMP>, including its headers files.
93 Your distribution may not provide these header files by default
94 and you may need to install a package called C<gmp-devel> or something
95 similar.  Alternatively, C<GMP> can be built from
96 source, available from L<http://gmplib.org/>.
98 =item 2 Configure
100 C<isl> uses the standard C<autoconf> C<configure> script.
101 To run it, just type
103         ./configure
105 optionally followed by some configure options.
106 A complete list of options can be obtained by running
108         ./configure --help
110 Below we discuss some of the more common options.
112 C<isl> can optionally use C<piplib>, but no
113 C<piplib> functionality is currently used by default.
114 The C<--with-piplib> option can
115 be used to specify which C<piplib>
116 library to use, either an installed version (C<system>),
117 an externally built version (C<build>)
118 or no version (C<no>).  The option C<build> is mostly useful
119 in C<configure> scripts of larger projects that bundle both C<isl>
120 and C<piplib>.
122 =over
124 =item C<--prefix>
126 Installation prefix for C<isl>
128 =item C<--with-gmp-prefix>
130 Installation prefix for C<GMP> (architecture-independent files).
132 =item C<--with-gmp-exec-prefix>
134 Installation prefix for C<GMP> (architecture-dependent files).
136 =item C<--with-piplib>
138 Which copy of C<piplib> to use, either C<no> (default), C<system> or C<build>.
140 =item C<--with-piplib-prefix>
142 Installation prefix for C<system> C<piplib> (architecture-independent files).
144 =item C<--with-piplib-exec-prefix>
146 Installation prefix for C<system> C<piplib> (architecture-dependent files).
148 =item C<--with-piplib-builddir>
150 Location where C<build> C<piplib> was built.
152 =back
154 =item 3 Compile
156         make
158 =item 4 Install (optional)
160         make install
162 =back
164 =head1 Library
166 =head2 Initialization
168 All manipulations of integer sets and relations occur within
169 the context of an C<isl_ctx>.
170 A given C<isl_ctx> can only be used within a single thread.
171 All arguments of a function are required to have been allocated
172 within the same context.
173 There are currently no functions available for moving an object
174 from one C<isl_ctx> to another C<isl_ctx>.  This means that
175 there is currently no way of safely moving an object from one
176 thread to another, unless the whole C<isl_ctx> is moved.
178 An C<isl_ctx> can be allocated using C<isl_ctx_alloc> and
179 freed using C<isl_ctx_free>.
180 All objects allocated within an C<isl_ctx> should be freed
181 before the C<isl_ctx> itself is freed.
183         isl_ctx *isl_ctx_alloc();
184         void isl_ctx_free(isl_ctx *ctx);
186 =head2 Integers
188 All operations on integers, mainly the coefficients
189 of the constraints describing the sets and relations,
190 are performed in exact integer arithmetic using C<GMP>.
191 However, to allow future versions of C<isl> to optionally
192 support fixed integer arithmetic, all calls to C<GMP>
193 are wrapped inside C<isl> specific macros.
194 The basic type is C<isl_int> and the following operations
195 are available on this type.
196 The meanings of these operations are essentially the same
197 as their C<GMP> C<mpz_> counterparts.
198 As always with C<GMP> types, C<isl_int>s need to be
199 initialized with C<isl_int_init> before they can be used
200 and they need to be released with C<isl_int_clear>
201 after the last use.
203 =over
205 =item isl_int_init(i)
207 =item isl_int_clear(i)
209 =item isl_int_set(r,i)
211 =item isl_int_set_si(r,i)
213 =item isl_int_abs(r,i)
215 =item isl_int_neg(r,i)
217 =item isl_int_swap(i,j)
219 =item isl_int_swap_or_set(i,j)
221 =item isl_int_add_ui(r,i,j)
223 =item isl_int_sub_ui(r,i,j)
225 =item isl_int_add(r,i,j)
227 =item isl_int_sub(r,i,j)
229 =item isl_int_mul(r,i,j)
231 =item isl_int_mul_ui(r,i,j)
233 =item isl_int_addmul(r,i,j)
235 =item isl_int_submul(r,i,j)
237 =item isl_int_gcd(r,i,j)
239 =item isl_int_lcm(r,i,j)
241 =item isl_int_divexact(r,i,j)
243 =item isl_int_cdiv_q(r,i,j)
245 =item isl_int_fdiv_q(r,i,j)
247 =item isl_int_fdiv_r(r,i,j)
249 =item isl_int_fdiv_q_ui(r,i,j)
251 =item isl_int_read(r,s)
253 =item isl_int_print(out,i,width)
255 =item isl_int_sgn(i)
257 =item isl_int_cmp(i,j)
259 =item isl_int_cmp_si(i,si)
261 =item isl_int_eq(i,j)
263 =item isl_int_ne(i,j)
265 =item isl_int_lt(i,j)
267 =item isl_int_le(i,j)
269 =item isl_int_gt(i,j)
271 =item isl_int_ge(i,j)
273 =item isl_int_abs_eq(i,j)
275 =item isl_int_abs_ne(i,j)
277 =item isl_int_abs_lt(i,j)
279 =item isl_int_abs_gt(i,j)
281 =item isl_int_abs_ge(i,j)
283 =item isl_int_is_zero(i)
285 =item isl_int_is_one(i)
287 =item isl_int_is_negone(i)
289 =item isl_int_is_pos(i)
291 =item isl_int_is_neg(i)
293 =item isl_int_is_nonpos(i)
295 =item isl_int_is_nonneg(i)
297 =item isl_int_is_divisible_by(i,j)
299 =back
301 =head2 Sets and Relations
303 C<isl> uses four types of objects for representing sets and relations,
304 C<isl_basic_set>, C<isl_basic_map>, C<isl_set> and C<isl_map>.
305 C<isl_basic_set> and C<isl_basic_map> represent sets and relations that
306 can be described as a conjunction of affine constraints, while
307 C<isl_set> and C<isl_map> represent unions of
308 C<isl_basic_set>s and C<isl_basic_map>s, respectively.
309 The difference between sets and relations (maps) is that sets have
310 one set of variables, while relations have two sets of variables,
311 input variables and output variables.
313 =head2 Memory Management
315 Since a high-level operation on sets and/or relations usually involves
316 several substeps and since the user is usually not interested in
317 the intermediate results, most functions that return a new object
318 will also release all the objects passed as arguments.
319 If the user still wants to use one or more of these arguments
320 after the function call, she should pass along a copy of the
321 object rather than the object itself.
322 The user is then responsible for make sure that the original
323 object gets used somewhere else or is explicitly freed.
325 The arguments and return values of all documents functions are
326 annotated to make clear which arguments are released and which
327 arguments are preserved.  In particular, the following annotations
328 are used
330 =over
332 =item C<__isl_give>
334 C<__isl_give> means that a new object is returned.
335 The user should make sure that the returned pointer is
336 used exactly once as a value for an C<__isl_take> argument.
337 In between, it can be used as a value for as many
338 C<__isl_keep> arguments as the user likes.
339 There is one exception, and that is the case where the
340 pointer returned is C<NULL>.  Is this case, the user
341 is free to use it as an C<__isl_take> argument or not.
343 =item C<__isl_take>
345 C<__isl_take> means that the object the argument points to
346 is taken over by the function and may no longer be used
347 by the user as an argument to any other function.
348 The pointer value must be one returned by a function
349 returning an C<__isl_give> pointer.
350 If the user passes in a C<NULL> value, then this will
351 be treated as an error in the sense that the function will
352 not perform its usual operation.  However, it will still
353 make sure that all the the other C<__isl_take> arguments
354 are released.
356 =item C<__isl_keep>
358 C<__isl_keep> means that the function will only use the object
359 temporarily.  After the function has finished, the user
360 can still use it as an argument to other functions.
361 A C<NULL> value will be treated in the same way as
362 a C<NULL> value for an C<__isl_take> argument.
364 =back
366 =head2 Dimension Specifications
368 Whenever a new set or relation is created from scratch,
369 its dimension needs to be specified using an C<isl_dim>.
371         #include <isl_dim.h>
372         __isl_give isl_dim *isl_dim_alloc(isl_ctx *ctx,
373                 unsigned nparam, unsigned n_in, unsigned n_out);
374         __isl_give isl_dim *isl_dim_set_alloc(isl_ctx *ctx,
375                 unsigned nparam, unsigned dim);
376         __isl_give isl_dim *isl_dim_copy(__isl_keep isl_dim *dim);
377         void isl_dim_free(__isl_take isl_dim *dim);
378         unsigned isl_dim_size(__isl_keep isl_dim *dim,
379                 enum isl_dim_type type);
381 The dimension specification used for creating a set
382 needs to be created using C<isl_dim_set_alloc>, while
383 that for creating a relation
384 needs to be created using C<isl_dim_alloc>.
385 C<isl_dim_size> can be used
386 to find out the number of dimensions of each type in
387 a dimension specification, where type may be
388 C<isl_dim_param>, C<isl_dim_in> (only for relations),
389 C<isl_dim_out> (only for relations), C<isl_dim_set>
390 (only for sets) or C<isl_dim_all>.
392 It is often useful to create objects that live in the
393 same space as some other object.  This can be accomplished
394 by creating the new objects
395 (see L<Creating New Sets and Relations> or
396 L<Creating New (Piecewise) Quasipolynomials>) based on the dimension
397 specification of the original object.
399         #include <isl_set.h>
400         __isl_give isl_dim *isl_basic_set_get_dim(
401                 __isl_keep isl_basic_set *bset);
402         __isl_give isl_dim *isl_set_get_dim(__isl_keep isl_set *set);
404         #include <isl_map.h>
405         __isl_give isl_dim *isl_basic_map_get_dim(
406                 __isl_keep isl_basic_map *bmap);
407         __isl_give isl_dim *isl_map_get_dim(__isl_keep isl_map *map);
409         #include <isl_polynomial.h>
410         __isl_give isl_dim *isl_qpolynomial_get_dim(
411                 __isl_keep isl_qpolynomial *qp);
412         __isl_give isl_dim *isl_pw_qpolynomial_get_dim(
413                 __isl_keep isl_pw_qpolynomial *pwqp);
415 The names of the individual dimensions may be set or read off
416 using the following functions.
418         #include <isl_dim.h>
419         __isl_give isl_dim *isl_dim_set_name(__isl_take isl_dim *dim,
420                                  enum isl_dim_type type, unsigned pos,
421                                  __isl_keep const char *name);
422         __isl_keep const char *isl_dim_get_name(__isl_keep isl_dim *dim,
423                                  enum isl_dim_type type, unsigned pos);
425 Note that C<isl_dim_get_name> returns a pointer to some internal
426 data structure, so the result can only be used while the
427 corresponding C<isl_dim> is alive.
428 Also note that every function that operates on two sets or relations
429 requires that both arguments have the same parameters.  This also
430 means that if one of the arguments has named parameters, then the
431 other needs to have named parameters too and the names need to match.
433 =head2 Input and Output
435 C<isl> supports its own input/output format, which is similar
436 to the C<Omega> format, but also supports the C<PolyLib> format
437 in some cases.
439 =head3 C<isl> format
441 The C<isl> format is similar to that of C<Omega>, but has a different
442 syntax for describing the parameters and allows for the definition
443 of an existentially quantified variable as the integer division
444 of an affine expression.
445 For example, the set of integers C<i> between C<0> and C<n>
446 such that C<i % 10 <= 6> can be described as
448         [n] -> { [i] : exists (a = [i/10] : 0 <= i and i <= n and
449                                 i - 10 a <= 6) }
451 A set or relation can have several disjuncts, separated
452 by the keyword C<or>.  Each disjunct is either a conjunction
453 of constraints or a projection (C<exists>) of a conjunction
454 of constraints.  The constraints are separated by the keyword
455 C<and>.
457 =head3 C<PolyLib> format
459 If the represented set is a union, then the first line
460 contains a single number representing the number of disjuncts.
461 Otherwise, a line containing the number C<1> is optional.
463 Each disjunct is represented by a matrix of constraints.
464 The first line contains two numbers representing
465 the number of rows and columns,
466 where the number of rows is equal to the number of constraints
467 and the number of columns is equal to two plus the number of variables.
468 The following lines contain the actual rows of the constraint matrix.
469 In each row, the first column indicates whether the constraint
470 is an equality (C<0>) or inequality (C<1>).  The final column
471 corresponds to the constant term.
473 If the set is parametric, then the coefficients of the parameters
474 appear in the last columns before the constant column.
475 The coefficients of any existentially quantified variables appear
476 between those of the set variables and those of the parameters.
478 =head3 Input
480         #include <isl_set.h>
481         __isl_give isl_basic_set *isl_basic_set_read_from_file(
482                 isl_ctx *ctx, FILE *input, int nparam);
483         __isl_give isl_basic_set *isl_basic_set_read_from_str(
484                 isl_ctx *ctx, const char *str, int nparam);
485         __isl_give isl_set *isl_set_read_from_file(isl_ctx *ctx,
486                 FILE *input, int nparam);
487         __isl_give isl_set *isl_set_read_from_str(isl_ctx *ctx,
488                 const char *str, int nparam);
490         #include <isl_map.h>
491         __isl_give isl_basic_map *isl_basic_map_read_from_file(
492                 isl_ctx *ctx, FILE *input, int nparam);
493         __isl_give isl_basic_map *isl_basic_map_read_from_str(
494                 isl_ctx *ctx, const char *str, int nparam);
495         __isl_give isl_map *isl_map_read_from_file(
496                 struct isl_ctx *ctx, FILE *input, int nparam);
497         __isl_give isl_map *isl_map_read_from_str(isl_ctx *ctx,
498                 const char *str, int nparam);
500 The input format is autodetected and may be either the C<PolyLib> format
501 or the C<isl> format.
502 C<nparam> specifies how many of the final columns in
503 the C<PolyLib> format correspond to parameters.
504 If input is given in the C<isl> format, then the number
505 of parameters needs to be equal to C<nparam>.
506 If C<nparam> is negative, then any number of parameters
507 is accepted in the C<isl> format and zero parameters
508 are assumed in the C<PolyLib> format.
510 =head3 Output
512 Before anything can be printed, an C<isl_printer> needs to
513 be created.
515         __isl_give isl_printer *isl_printer_to_file(isl_ctx *ctx,
516                 FILE *file);
517         __isl_give isl_printer *isl_printer_to_str(isl_ctx *ctx);
518         void isl_printer_free(__isl_take isl_printer *printer);
519         __isl_give char *isl_printer_get_str(
520                 __isl_keep isl_printer *printer);
522 The behavior of the printer can be modified in various ways
524         __isl_give isl_printer *isl_printer_set_output_format(
525                 __isl_take isl_printer *p, int output_format);
526         __isl_give isl_printer *isl_printer_set_indent(
527                 __isl_take isl_printer *p, int indent);
528         __isl_give isl_printer *isl_printer_set_prefix(
529                 __isl_take isl_printer *p, const char *prefix);
530         __isl_give isl_printer *isl_printer_set_suffix(
531                 __isl_take isl_printer *p, const char *suffix);
533 The C<output_format> may be either C<ISL_FORMAT_ISL>, C<ISL_FORMAT_OMEGA>
534 or C<ISL_FORMAT_POLYLIB> and defaults to C<ISL_FORMAT_ISL>.
535 Each line in the output is indented by C<indent> spaces
536 (default: 0), prefixed by C<prefix> and suffixed by C<suffix>.
537 In the C<PolyLib> format output,
538 the coefficients of the existentially quantified variables
539 appear between those of the set variables and those
540 of the parameters.
542 To actually print something, use
544         #include <isl_set.h>
545         __isl_give isl_printer *isl_printer_print_basic_set(
546                 __isl_take isl_printer *printer,
547                 __isl_keep isl_basic_set *bset);
548         __isl_give isl_printer *isl_printer_print_set(
549                 __isl_take isl_printer *printer,
550                 __isl_keep isl_set *set);
552         #include <isl_map.h>
553         __isl_give isl_printer *isl_printer_print_basic_map(
554                 __isl_take isl_printer *printer,
555                 __isl_keep isl_basic_map *bmap);
556         __isl_give isl_printer *isl_printer_print_map(
557                 __isl_take isl_printer *printer,
558                 __isl_keep isl_map *map);
560 When called on a file printer, the following function flushes
561 the file.  When called on a string printer, the buffer is cleared.
563         __isl_give isl_printer *isl_printer_flush(
564                 __isl_take isl_printer *p);
566 =head2 Creating New Sets and Relations
568 C<isl> has functions for creating some standard sets and relations.
570 =over
572 =item * Empty sets and relations
574         __isl_give isl_basic_set *isl_basic_set_empty(
575                 __isl_take isl_dim *dim);
576         __isl_give isl_basic_map *isl_basic_map_empty(
577                 __isl_take isl_dim *dim);
578         __isl_give isl_set *isl_set_empty(
579                 __isl_take isl_dim *dim);
580         __isl_give isl_map *isl_map_empty(
581                 __isl_take isl_dim *dim);
583 =item * Universe sets and relations
585         __isl_give isl_basic_set *isl_basic_set_universe(
586                 __isl_take isl_dim *dim);
587         __isl_give isl_basic_map *isl_basic_map_universe(
588                 __isl_take isl_dim *dim);
589         __isl_give isl_set *isl_set_universe(
590                 __isl_take isl_dim *dim);
591         __isl_give isl_map *isl_map_universe(
592                 __isl_take isl_dim *dim);
594 =item * Identity relations
596         __isl_give isl_basic_map *isl_basic_map_identity(
597                 __isl_take isl_dim *set_dim);
598         __isl_give isl_map *isl_map_identity(
599                 __isl_take isl_dim *set_dim);
601 These functions take a dimension specification for a B<set>
602 and return an identity relation between two such sets.
604 =item * Lexicographic order
606         __isl_give isl_map *isl_map_lex_lt(
607                 __isl_take isl_dim *set_dim);
608         __isl_give isl_map *isl_map_lex_le(
609                 __isl_take isl_dim *set_dim);
610         __isl_give isl_map *isl_map_lex_gt(
611                 __isl_take isl_dim *set_dim);
612         __isl_give isl_map *isl_map_lex_ge(
613                 __isl_take isl_dim *set_dim);
614         __isl_give isl_map *isl_map_lex_lt_first(
615                 __isl_take isl_dim *dim, unsigned n);
616         __isl_give isl_map *isl_map_lex_le_first(
617                 __isl_take isl_dim *dim, unsigned n);
618         __isl_give isl_map *isl_map_lex_gt_first(
619                 __isl_take isl_dim *dim, unsigned n);
620         __isl_give isl_map *isl_map_lex_ge_first(
621                 __isl_take isl_dim *dim, unsigned n);
623 The first four functions take a dimension specification for a B<set>
624 and return relations that express that the elements in the domain
625 are lexicographically less
626 (C<isl_map_lex_lt>), less or equal (C<isl_map_lex_le>),
627 greater (C<isl_map_lex_gt>) or greater or equal (C<isl_map_lex_ge>)
628 than the elements in the range.
629 The last four functions take a dimension specification for a map
630 and return relations that express that the first C<n> dimensions
631 in the domain are lexicographically less
632 (C<isl_map_lex_lt_first>), less or equal (C<isl_map_lex_le_first>),
633 greater (C<isl_map_lex_gt_first>) or greater or equal (C<isl_map_lex_ge_first>)
634 than the first C<n> dimensions in the range.
636 =back
638 A basic set or relation can be converted to a set or relation
639 using the following functions.
641         __isl_give isl_set *isl_set_from_basic_set(
642                 __isl_take isl_basic_set *bset);
643         __isl_give isl_map *isl_map_from_basic_map(
644                 __isl_take isl_basic_map *bmap);
646 Sets and relations can be copied and freed again using the following
647 functions.
649         __isl_give isl_basic_set *isl_basic_set_copy(
650                 __isl_keep isl_basic_set *bset);
651         __isl_give isl_set *isl_set_copy(__isl_keep isl_set *set);
652         __isl_give isl_basic_map *isl_basic_map_copy(
653                 __isl_keep isl_basic_map *bmap);
654         __isl_give isl_map *isl_map_copy(__isl_keep isl_map *map);
655         void isl_basic_set_free(__isl_take isl_basic_set *bset);
656         void isl_set_free(__isl_take isl_set *set);
657         void isl_basic_map_free(__isl_take isl_basic_map *bmap);
658         void isl_map_free(__isl_take isl_map *map);
660 Other sets and relations can be constructed by starting
661 from a universe set or relation, adding equality and/or
662 inequality constraints and then projecting out the
663 existentially quantified variables, if any.
664 Constraints can be constructed, manipulated and
665 added to basic sets and relations using the following functions.
667         #include <isl_constraint.h>
668         __isl_give isl_constraint *isl_equality_alloc(
669                 __isl_take isl_dim *dim);
670         __isl_give isl_constraint *isl_inequality_alloc(
671                 __isl_take isl_dim *dim);
672         void isl_constraint_set_constant(
673                 __isl_keep isl_constraint *constraint, isl_int v);
674         void isl_constraint_set_coefficient(
675                 __isl_keep isl_constraint *constraint,
676                 enum isl_dim_type type, int pos, isl_int v);
677         __isl_give isl_basic_map *isl_basic_map_add_constraint(
678                 __isl_take isl_basic_map *bmap,
679                 __isl_take isl_constraint *constraint);
680         __isl_give isl_basic_set *isl_basic_set_add_constraint(
681                 __isl_take isl_basic_set *bset,
682                 __isl_take isl_constraint *constraint);
684 For example, to create a set containing the even integers
685 between 10 and 42, you would use the following code.
687         isl_int v;
688         struct isl_dim *dim;
689         struct isl_constraint *c;
690         struct isl_basic_set *bset;
692         isl_int_init(v);
693         dim = isl_dim_set_alloc(ctx, 0, 2);
694         bset = isl_basic_set_universe(isl_dim_copy(dim));
696         c = isl_equality_alloc(isl_dim_copy(dim));
697         isl_int_set_si(v, -1);
698         isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
699         isl_int_set_si(v, 2);
700         isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
701         bset = isl_basic_set_add_constraint(bset, c);
703         c = isl_inequality_alloc(isl_dim_copy(dim));
704         isl_int_set_si(v, -10);
705         isl_constraint_set_constant(c, v);
706         isl_int_set_si(v, 1);
707         isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
708         bset = isl_basic_set_add_constraint(bset, c);
710         c = isl_inequality_alloc(dim);
711         isl_int_set_si(v, 42);
712         isl_constraint_set_constant(c, v);
713         isl_int_set_si(v, -1);
714         isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
715         bset = isl_basic_set_add_constraint(bset, c);
717         bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 1);
719         isl_int_clear(v);
721 Or, alternatively,
723         struct isl_basic_set *bset;
724         bset = isl_basic_set_read_from_str(ctx,
725                 "{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}", -1);
727 =head2 Inspecting Sets and Relations
729 Usually, the user should not have to care about the actual constraints
730 of the sets and maps, but should instead apply the abstract operations
731 explained in the following sections.
732 Occasionally, however, it may be required to inspect the individual
733 coefficients of the constraints.  This section explains how to do so.
734 In these cases, it may also be useful to have C<isl> compute
735 an explicit representation of the existentially quantified variables.
737         __isl_give isl_set *isl_set_compute_divs(
738                 __isl_take isl_set *set);
739         __isl_give isl_map *isl_map_compute_divs(
740                 __isl_take isl_map *map);
742 This explicit representation defines the existentially quantified
743 variables as integer divisions of the other variables, possibly
744 including earlier existentially quantified variables.
745 An explicitly represented existentially quantified variable therefore
746 has a unique value when the values of the other variables are known.
747 If, furthermore, the same existentials, i.e., existentials
748 with the same explicit representations, should appear in the
749 same order in each of the disjuncts of a set or map, then the user should call
750 either of the following functions.
752         __isl_give isl_set *isl_set_align_divs(
753                 __isl_take isl_set *set);
754         __isl_give isl_map *isl_map_align_divs(
755                 __isl_take isl_map *map);
757 To iterate over all the basic sets or maps in a set or map, use
759         int isl_set_foreach_basic_set(__isl_keep isl_set *set,
760                 int (*fn)(__isl_take isl_basic_set *bset, void *user),
761                 void *user);
762         int isl_map_foreach_basic_map(__isl_keep isl_map *map,
763                 int (*fn)(__isl_take isl_basic_map *bmap, void *user),
764                 void *user);
766 The callback function C<fn> should return 0 if successful and
767 -1 if an error occurs.  In the latter case, or if any other error
768 occurs, the above functions will return -1.
770 It should be noted that C<isl> does not guarantee that
771 the basic sets or maps passed to C<fn> are disjoint.
772 If this is required, then the user should call one of
773 the following functions first.
775         __isl_give isl_set *isl_set_make_disjoint(
776                 __isl_take isl_set *set);
777         __isl_give isl_map *isl_map_make_disjoint(
778                 __isl_take isl_map *map);
780 To iterate over the constraints of a basic set or map, use
782         #include <isl_constraint.h>
784         int isl_basic_map_foreach_constraint(
785                 __isl_keep isl_basic_map *bmap,
786                 int (*fn)(__isl_take isl_constraint *c, void *user),
787                 void *user);
788         void isl_constraint_free(struct isl_constraint *c);
790 Again, the callback function C<fn> should return 0 if successful and
791 -1 if an error occurs.  In the latter case, or if any other error
792 occurs, the above functions will return -1.
793 The constraint C<c> represents either an equality or an inequality.
794 Use the following function to find out whether a constraint
795 represents an equality.  If not, it represents an inequality.
797         int isl_constraint_is_equality(
798                 __isl_keep isl_constraint *constraint);
800 The coefficients of the constraints can be inspected using
801 the following functions.
803         void isl_constraint_get_constant(
804                 __isl_keep isl_constraint *constraint, isl_int *v);
805         void isl_constraint_get_coefficient(
806                 __isl_keep isl_constraint *constraint,
807                 enum isl_dim_type type, int pos, isl_int *v);
809 The explicit representations of the existentially quantified
810 variables can be inspected using the following functions.
811 Note that the user is only allowed to use these functions
812 if the inspected set or map is the result of a call
813 to C<isl_set_compute_divs> or C<isl_map_compute_divs>.
815         __isl_give isl_div *isl_constraint_div(
816                 __isl_keep isl_constraint *constraint, int pos);
817         void isl_div_get_constant(__isl_keep isl_div *div,
818                 isl_int *v);
819         void isl_div_get_denominator(__isl_keep isl_div *div,
820                 isl_int *v);
821         void isl_div_get_coefficient(__isl_keep isl_div *div,
822                 enum isl_dim_type type, int pos, isl_int *v);
824 =head2 Properties
826 =head3 Unary Properties
828 =over
830 =item * Emptiness
832 The following functions test whether the given set or relation
833 contains any integer points.  The ``fast'' variants do not perform
834 any computations, but simply check if the given set or relation
835 is already known to be empty.
837         int isl_basic_set_fast_is_empty(__isl_keep isl_basic_set *bset);
838         int isl_basic_set_is_empty(__isl_keep isl_basic_set *bset);
839         int isl_set_is_empty(__isl_keep isl_set *set);
840         int isl_basic_map_fast_is_empty(__isl_keep isl_basic_map *bmap);
841         int isl_basic_map_is_empty(__isl_keep isl_basic_map *bmap);
842         int isl_map_fast_is_empty(__isl_keep isl_map *map);
843         int isl_map_is_empty(__isl_keep isl_map *map);
845 =item * Universality
847         int isl_basic_set_is_universe(__isl_keep isl_basic_set *bset);
848         int isl_basic_map_is_universe(__isl_keep isl_basic_map *bmap);
849         int isl_set_fast_is_universe(__isl_keep isl_set *set);
851 =item * Single-valuedness
853         int isl_map_is_single_valued(__isl_keep isl_map *map);
855 =item * Bijectivity
857         int isl_map_is_bijective(__isl_keep isl_map *map);
859 =back
861 =head3 Binary Properties
863 =over
865 =item * Equality
867         int isl_set_fast_is_equal(__isl_keep isl_set *set1,
868                 __isl_keep isl_set *set2);
869         int isl_set_is_equal(__isl_keep isl_set *set1,
870                 __isl_keep isl_set *set2);
871         int isl_map_is_equal(__isl_keep isl_map *map1,
872                 __isl_keep isl_map *map2);
873         int isl_map_fast_is_equal(__isl_keep isl_map *map1,
874                 __isl_keep isl_map *map2);
875         int isl_basic_map_is_equal(
876                 __isl_keep isl_basic_map *bmap1,
877                 __isl_keep isl_basic_map *bmap2);
879 =item * Disjointness
881         int isl_set_fast_is_disjoint(__isl_keep isl_set *set1,
882                 __isl_keep isl_set *set2);
884 =item * Subset
886         int isl_set_is_subset(__isl_keep isl_set *set1,
887                 __isl_keep isl_set *set2);
888         int isl_set_is_strict_subset(
889                 __isl_keep isl_set *set1,
890                 __isl_keep isl_set *set2);
891         int isl_basic_map_is_subset(
892                 __isl_keep isl_basic_map *bmap1,
893                 __isl_keep isl_basic_map *bmap2);
894         int isl_basic_map_is_strict_subset(
895                 __isl_keep isl_basic_map *bmap1,
896                 __isl_keep isl_basic_map *bmap2);
897         int isl_map_is_subset(
898                 __isl_keep isl_map *map1,
899                 __isl_keep isl_map *map2);
900         int isl_map_is_strict_subset(
901                 __isl_keep isl_map *map1,
902                 __isl_keep isl_map *map2);
904 =back
906 =head2 Unary Operations
908 =over
910 =item * Complement
912         __isl_give isl_set *isl_set_complement(
913                 __isl_take isl_set *set);
915 =item * Inverse map
917         __isl_give isl_basic_map *isl_basic_map_reverse(
918                 __isl_take isl_basic_map *bmap);
919         __isl_give isl_map *isl_map_reverse(
920                 __isl_take isl_map *map);
922 =item * Projection
924         __isl_give isl_basic_set *isl_basic_set_project_out(
925                 __isl_take isl_basic_set *bset,
926                 enum isl_dim_type type, unsigned first, unsigned n);
927         __isl_give isl_basic_map *isl_basic_map_project_out(
928                 __isl_take isl_basic_map *bmap,
929                 enum isl_dim_type type, unsigned first, unsigned n);
930         __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set,
931                 enum isl_dim_type type, unsigned first, unsigned n);
932         __isl_give isl_map *isl_map_project_out(__isl_take isl_map *map,
933                 enum isl_dim_type type, unsigned first, unsigned n);
934         __isl_give isl_basic_set *isl_basic_map_domain(
935                 __isl_take isl_basic_map *bmap);
936         __isl_give isl_basic_set *isl_basic_map_range(
937                 __isl_take isl_basic_map *bmap);
938         __isl_give isl_set *isl_map_domain(
939                 __isl_take isl_map *bmap);
940         __isl_give isl_set *isl_map_range(
941                 __isl_take isl_map *map);
943 =item * Deltas
945         __isl_give isl_basic_set *isl_basic_map_deltas(
946                 __isl_take isl_basic_map *bmap);
947         __isl_give isl_set *isl_map_deltas(__isl_take isl_map *map);
949 These functions return a (basic) set containing the differences
950 between image elements and corresponding domain elements in the input.
952 =item * Coalescing
954 Simplify the representation of a set or relation by trying
955 to combine pairs of basic sets or relations into a single
956 basic set or relation.
958         __isl_give isl_set *isl_set_coalesce(__isl_take isl_set *set);
959         __isl_give isl_map *isl_map_coalesce(__isl_take isl_map *map);
961 =item * Convex hull
963         __isl_give isl_basic_set *isl_set_convex_hull(
964                 __isl_take isl_set *set);
965         __isl_give isl_basic_map *isl_map_convex_hull(
966                 __isl_take isl_map *map);
968 If the input set or relation has any existentially quantified
969 variables, then the result of these operations is currently undefined.
971 =item * Simple hull
973         __isl_give isl_basic_set *isl_set_simple_hull(
974                 __isl_take isl_set *set);
975         __isl_give isl_basic_map *isl_map_simple_hull(
976                 __isl_take isl_map *map);
978 These functions compute a single basic set or relation
979 that contains the whole input set or relation.
980 In particular, the output is described by translates
981 of the constraints describing the basic sets or relations in the input.
983 =begin latex
985 (See \autoref{s:simple hull}.)
987 =end latex
989 =item * Affine hull
991         __isl_give isl_basic_set *isl_basic_set_affine_hull(
992                 __isl_take isl_basic_set *bset);
993         __isl_give isl_basic_set *isl_set_affine_hull(
994                 __isl_take isl_set *set);
995         __isl_give isl_basic_map *isl_basic_map_affine_hull(
996                 __isl_take isl_basic_map *bmap);
997         __isl_give isl_basic_map *isl_map_affine_hull(
998                 __isl_take isl_map *map);
1000 =item * Power
1002         __isl_give isl_map *isl_map_power(__isl_take isl_map *map,
1003                 unsigned param, int *exact);
1005 Compute a parametric representation for all positive powers I<k> of C<map>.
1006 The power I<k> is equated to the parameter at position C<param>.
1007 The result may be an overapproximation.  If the result is exact,
1008 then C<*exact> is set to C<1>.
1009 The current implementation only produces exact results for particular
1010 cases of piecewise translations (i.e., piecewise uniform dependences).
1012 =item * Transitive closure
1014         __isl_give isl_map *isl_map_transitive_closure(
1015                 __isl_take isl_map *map, int *exact);
1017 Compute the transitive closure of C<map>.
1018 The result may be an overapproximation.  If the result is known to be exact,
1019 then C<*exact> is set to C<1>.
1020 The current implementation only produces exact results for particular
1021 cases of piecewise translations (i.e., piecewise uniform dependences).
1023 =item * Reaching path lengths
1025         __isl_give isl_map *isl_map_reaching_path_lengths(
1026                 __isl_take isl_map *map, int *exact);
1028 Compute a relation that maps each element in the range of C<map>
1029 to the lengths of all paths composed of edges in C<map> that
1030 end up in the given element.
1031 The result may be an overapproximation.  If the result is known to be exact,
1032 then C<*exact> is set to C<1>.
1033 To compute the I<maximal> path length, the resulting relation
1034 should be postprocessed by C<isl_map_lexmax>.
1035 In particular, if the input relation is a dependence relation
1036 (mapping sources to sinks), then the maximal path length corresponds
1037 to the free schedule.
1038 Note, however, that C<isl_map_lexmax> expects the maximum to be
1039 finite, so if the path lengths are unbounded (possibly due to
1040 the overapproximation), then you will get an error message.
1042 =back
1044 =head2 Binary Operations
1046 The two arguments of a binary operation not only need to live
1047 in the same C<isl_ctx>, they currently also need to have
1048 the same (number of) parameters.
1050 =head3 Basic Operations
1052 =over
1054 =item * Intersection
1056         __isl_give isl_basic_set *isl_basic_set_intersect(
1057                 __isl_take isl_basic_set *bset1,
1058                 __isl_take isl_basic_set *bset2);
1059         __isl_give isl_set *isl_set_intersect(
1060                 __isl_take isl_set *set1,
1061                 __isl_take isl_set *set2);
1062         __isl_give isl_basic_map *isl_basic_map_intersect_domain(
1063                 __isl_take isl_basic_map *bmap,
1064                 __isl_take isl_basic_set *bset);
1065         __isl_give isl_basic_map *isl_basic_map_intersect_range(
1066                 __isl_take isl_basic_map *bmap,
1067                 __isl_take isl_basic_set *bset);
1068         __isl_give isl_basic_map *isl_basic_map_intersect(
1069                 __isl_take isl_basic_map *bmap1,
1070                 __isl_take isl_basic_map *bmap2);
1071         __isl_give isl_map *isl_map_intersect_domain(
1072                 __isl_take isl_map *map,
1073                 __isl_take isl_set *set);
1074         __isl_give isl_map *isl_map_intersect_range(
1075                 __isl_take isl_map *map,
1076                 __isl_take isl_set *set);
1077         __isl_give isl_map *isl_map_intersect(
1078                 __isl_take isl_map *map1,
1079                 __isl_take isl_map *map2);
1081 =item * Union
1083         __isl_give isl_set *isl_basic_set_union(
1084                 __isl_take isl_basic_set *bset1,
1085                 __isl_take isl_basic_set *bset2);
1086         __isl_give isl_map *isl_basic_map_union(
1087                 __isl_take isl_basic_map *bmap1,
1088                 __isl_take isl_basic_map *bmap2);
1089         __isl_give isl_set *isl_set_union(
1090                 __isl_take isl_set *set1,
1091                 __isl_take isl_set *set2);
1092         __isl_give isl_map *isl_map_union(
1093                 __isl_take isl_map *map1,
1094                 __isl_take isl_map *map2);
1096 =item * Set difference
1098         __isl_give isl_set *isl_set_subtract(
1099                 __isl_take isl_set *set1,
1100                 __isl_take isl_set *set2);
1101         __isl_give isl_map *isl_map_subtract(
1102                 __isl_take isl_map *map1,
1103                 __isl_take isl_map *map2);
1105 =item * Application
1107         __isl_give isl_basic_set *isl_basic_set_apply(
1108                 __isl_take isl_basic_set *bset,
1109                 __isl_take isl_basic_map *bmap);
1110         __isl_give isl_set *isl_set_apply(
1111                 __isl_take isl_set *set,
1112                 __isl_take isl_map *map);
1113         __isl_give isl_basic_map *isl_basic_map_apply_domain(
1114                 __isl_take isl_basic_map *bmap1,
1115                 __isl_take isl_basic_map *bmap2);
1116         __isl_give isl_basic_map *isl_basic_map_apply_range(
1117                 __isl_take isl_basic_map *bmap1,
1118                 __isl_take isl_basic_map *bmap2);
1119         __isl_give isl_map *isl_map_apply_domain(
1120                 __isl_take isl_map *map1,
1121                 __isl_take isl_map *map2);
1122         __isl_give isl_map *isl_map_apply_range(
1123                 __isl_take isl_map *map1,
1124                 __isl_take isl_map *map2);
1126 =item * Simplification
1128         __isl_give isl_basic_set *isl_basic_set_gist(
1129                 __isl_take isl_basic_set *bset,
1130                 __isl_take isl_basic_set *context);
1131         __isl_give isl_set *isl_set_gist(__isl_take isl_set *set,
1132                 __isl_take isl_set *context);
1133         __isl_give isl_basic_map *isl_basic_map_gist(
1134                 __isl_take isl_basic_map *bmap,
1135                 __isl_take isl_basic_map *context);
1136         __isl_give isl_map *isl_map_gist(__isl_take isl_map *map,
1137                 __isl_take isl_map *context);
1139 The gist operation returns a set or relation that has the
1140 same intersection with the context as the input set or relation.
1141 Any implicit equality in the intersection is made explicit in the result,
1142 while all inequalities that are redundant with respect to the intersection
1143 are removed.
1145 =back
1147 =head3 Lexicographic Optimization
1149 Given a (basic) set C<set> (or C<bset>) and a zero-dimensional domain C<dom>,
1150 the following functions
1151 compute a set that contains the lexicographic minimum or maximum
1152 of the elements in C<set> (or C<bset>) for those values of the parameters
1153 that satisfy C<dom>.
1154 If C<empty> is not C<NULL>, then C<*empty> is assigned a set
1155 that contains the parameter values in C<dom> for which C<set> (or C<bset>)
1156 has no elements.
1157 In other words, the union of the parameter values
1158 for which the result is non-empty and of C<*empty>
1159 is equal to C<dom>.
1161         __isl_give isl_set *isl_basic_set_partial_lexmin(
1162                 __isl_take isl_basic_set *bset,
1163                 __isl_take isl_basic_set *dom,
1164                 __isl_give isl_set **empty);
1165         __isl_give isl_set *isl_basic_set_partial_lexmax(
1166                 __isl_take isl_basic_set *bset,
1167                 __isl_take isl_basic_set *dom,
1168                 __isl_give isl_set **empty);
1169         __isl_give isl_set *isl_set_partial_lexmin(
1170                 __isl_take isl_set *set, __isl_take isl_set *dom,
1171                 __isl_give isl_set **empty);
1172         __isl_give isl_set *isl_set_partial_lexmax(
1173                 __isl_take isl_set *set, __isl_take isl_set *dom,
1174                 __isl_give isl_set **empty);
1176 Given a (basic) set C<set> (or C<bset>), the following functions simply
1177 return a set containing the lexicographic minimum or maximum
1178 of the elements in C<set> (or C<bset>).
1180         __isl_give isl_set *isl_basic_set_lexmin(
1181                 __isl_take isl_basic_set *bset);
1182         __isl_give isl_set *isl_basic_set_lexmax(
1183                 __isl_take isl_basic_set *bset);
1184         __isl_give isl_set *isl_set_lexmin(
1185                 __isl_take isl_set *set);
1186         __isl_give isl_set *isl_set_lexmax(
1187                 __isl_take isl_set *set);
1189 Given a (basic) relation C<map> (or C<bmap>) and a domain C<dom>,
1190 the following functions
1191 compute a relation that maps each element of C<dom>
1192 to the single lexicographic minimum or maximum
1193 of the elements that are associated to that same
1194 element in C<map> (or C<bmap>).
1195 If C<empty> is not C<NULL>, then C<*empty> is assigned a set
1196 that contains the elements in C<dom> that do not map
1197 to any elements in C<map> (or C<bmap>).
1198 In other words, the union of the domain of the result and of C<*empty>
1199 is equal to C<dom>.
1201         __isl_give isl_map *isl_basic_map_partial_lexmax(
1202                 __isl_take isl_basic_map *bmap,
1203                 __isl_take isl_basic_set *dom,
1204                 __isl_give isl_set **empty);
1205         __isl_give isl_map *isl_basic_map_partial_lexmin(
1206                 __isl_take isl_basic_map *bmap,
1207                 __isl_take isl_basic_set *dom,
1208                 __isl_give isl_set **empty);
1209         __isl_give isl_map *isl_map_partial_lexmax(
1210                 __isl_take isl_map *map, __isl_take isl_set *dom,
1211                 __isl_give isl_set **empty);
1212         __isl_give isl_map *isl_map_partial_lexmin(
1213                 __isl_take isl_map *map, __isl_take isl_set *dom,
1214                 __isl_give isl_set **empty);
1216 Given a (basic) map C<map> (or C<bmap>), the following functions simply
1217 return a map mapping each element in the domain of
1218 C<map> (or C<bmap>) to the lexicographic minimum or maximum
1219 of all elements associated to that element.
1221         __isl_give isl_map *isl_basic_map_lexmin(
1222                 __isl_take isl_basic_map *bmap);
1223         __isl_give isl_map *isl_basic_map_lexmax(
1224                 __isl_take isl_basic_map *bmap);
1225         __isl_give isl_map *isl_map_lexmin(
1226                 __isl_take isl_map *map);
1227         __isl_give isl_map *isl_map_lexmax(
1228                 __isl_take isl_map *map);
1230 =head2 Points
1232 Points are elements of a set.  They can be used to construct
1233 simple sets (boxes) or they can be used to represent the
1234 individual elements of a set.
1235 The zero point (the origin) can be created using
1237         __isl_give isl_point *isl_point_zero(__isl_take isl_dim *dim);
1239 The coordinates of a point can be inspected, set and changed
1240 using
1242         void isl_point_get_coordinate(__isl_keep isl_point *pnt,
1243                 enum isl_dim_type type, int pos, isl_int *v);
1244         __isl_give isl_point *isl_point_set_coordinate(
1245                 __isl_take isl_point *pnt,
1246                 enum isl_dim_type type, int pos, isl_int v);
1248         __isl_give isl_point *isl_point_add_ui(
1249                 __isl_take isl_point *pnt,
1250                 enum isl_dim_type type, int pos, unsigned val);
1251         __isl_give isl_point *isl_point_sub_ui(
1252                 __isl_take isl_point *pnt,
1253                 enum isl_dim_type type, int pos, unsigned val);
1255 Points can be copied or freed using
1257         __isl_give isl_point *isl_point_copy(
1258                 __isl_keep isl_point *pnt);
1259         void isl_point_free(__isl_take isl_point *pnt);
1261 A singleton set can be created from a point using
1263         __isl_give isl_set *isl_set_from_point(
1264                 __isl_take isl_point *pnt);
1266 and a box can be created from two opposite extremal points using
1268         __isl_give isl_set *isl_set_box_from_points(
1269                 __isl_take isl_point *pnt1,
1270                 __isl_take isl_point *pnt2);
1272 All elements of a B<bounded> set can be enumerated using
1273 the following function.
1275         int isl_set_foreach_point(__isl_keep isl_set *set,
1276                 int (*fn)(__isl_take isl_point *pnt, void *user),
1277                 void *user);
1279 The function C<fn> is called for each integer point in
1280 C<set> with as second argument the last argument of
1281 the C<isl_set_foreach_point> call.  The function C<fn>
1282 should return C<0> on success and C<-1> on failure.
1283 In the latter case, C<isl_set_foreach_point> will stop
1284 enumerating and return C<-1> as well.
1285 If the enumeration is performed successfully and to completion,
1286 then C<isl_set_foreach_point> returns C<0>.
1288 To obtain a single point of a set, use
1290         __isl_give isl_point *isl_set_sample_point(
1291                 __isl_take isl_set *set);
1293 If C<set> does not contain any (integer) points, then the
1294 resulting point will be ``void'', a property that can be
1295 tested using
1297         int isl_point_is_void(__isl_keep isl_point *pnt);
1299 =head2 Piecewise Quasipolynomials
1301 A piecewise quasipolynomial is a particular kind of function that maps
1302 a parametric point to a rational value.
1303 More specifically, a quasipolynomial is a polynomial expression in greatest
1304 integer parts of affine expressions of parameters and variables.
1305 A piecewise quasipolynomial is a subdivision of a given parametric
1306 domain into disjoint cells with a quasipolynomial associated to
1307 each cell.  The value of the piecewise quasipolynomial at a given
1308 point is the value of the quasipolynomial associated to the cell
1309 that contains the point.  Outside of the union of cells,
1310 the value is assumed to be zero.
1311 For example, the piecewise quasipolynomial
1313         [n] -> { [x] -> ((1 + n) - x) : x <= n and x >= 0 }
1315 maps C<x> to C<1 + n - x> for values of C<x> between C<0> and C<n>.
1316 Piecewise quasipolynomials are mainly used by the C<barvinok>
1317 library for representing the number of elements in a parametric set or map.
1318 For example, the piecewise quasipolynomial above represents
1319 the number of points in the map
1321         [n] -> { [x] -> [y] : x,y >= 0 and 0 <= x + y <= n }
1323 =head3 Printing (Piecewise) Quasipolynomials
1325 Quasipolynomials and piecewise quasipolynomials can be printed
1326 using the following functions.
1328         __isl_give isl_printer *isl_printer_print_qpolynomial(
1329                 __isl_take isl_printer *p,
1330                 __isl_keep isl_qpolynomial *qp);
1332         __isl_give isl_printer *isl_printer_print_pw_qpolynomial(
1333                 __isl_take isl_printer *p,
1334                 __isl_keep isl_pw_qpolynomial *pwqp);
1336 The output format of the printer
1337 needs to be set to either C<ISL_FORMAT_ISL> or C<ISL_FORMAT_C>.
1339 =head3 Creating New (Piecewise) Quasipolynomials
1341 Some simple quasipolynomials can be created using the following functions.
1342 More complicated quasipolynomials can be created by applying
1343 operations such as addition and multiplication
1344 on the resulting quasipolynomials
1346         __isl_give isl_qpolynomial *isl_qpolynomial_zero(
1347                 __isl_take isl_dim *dim);
1348         __isl_give isl_qpolynomial *isl_qpolynomial_infty(
1349                 __isl_take isl_dim *dim);
1350         __isl_give isl_qpolynomial *isl_qpolynomial_neginfty(
1351                 __isl_take isl_dim *dim);
1352         __isl_give isl_qpolynomial *isl_qpolynomial_nan(
1353                 __isl_take isl_dim *dim);
1354         __isl_give isl_qpolynomial *isl_qpolynomial_rat_cst(
1355                 __isl_take isl_dim *dim,
1356                 const isl_int n, const isl_int d);
1357         __isl_give isl_qpolynomial *isl_qpolynomial_div(
1358                 __isl_take isl_div *div);
1359         __isl_give isl_qpolynomial *isl_qpolynomial_var(
1360                 __isl_take isl_dim *dim,
1361                 enum isl_dim_type type, unsigned pos);
1363 The zero piecewise quasipolynomial or a piecewise quasipolynomial
1364 with a single cell can be created using the following functions.
1365 Multiple of these single cell piecewise quasipolynomials can
1366 be combined to create more complicated piecewise quasipolynomials.
1368         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(
1369                 __isl_take isl_dim *dim);
1370         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_alloc(
1371                 __isl_take isl_set *set,
1372                 __isl_take isl_qpolynomial *qp);
1374 Quasipolynomials can be copied and freed again using the following
1375 functions.
1377         __isl_give isl_qpolynomial *isl_qpolynomial_copy(
1378                 __isl_keep isl_qpolynomial *qp);
1379         void isl_qpolynomial_free(__isl_take isl_qpolynomial *qp);
1381         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_copy(
1382                 __isl_keep isl_pw_qpolynomial *pwqp);
1383         void isl_pw_qpolynomial_free(
1384                 __isl_take isl_pw_qpolynomial *pwqp);
1386 =head3 Inspecting (Piecewise) Quasipolynomials
1388 To iterate over the cells in a piecewise quasipolynomial,
1389 use either of the following two functions
1391         int isl_pw_qpolynomial_foreach_piece(
1392                 __isl_keep isl_pw_qpolynomial *pwqp,
1393                 int (*fn)(__isl_take isl_set *set,
1394                           __isl_take isl_qpolynomial *qp,
1395                           void *user), void *user);
1396         int isl_pw_qpolynomial_foreach_lifted_piece(
1397                 __isl_keep isl_pw_qpolynomial *pwqp,
1398                 int (*fn)(__isl_take isl_set *set,
1399                           __isl_take isl_qpolynomial *qp,
1400                           void *user), void *user);
1402 As usual, the function C<fn> should return C<0> on success
1403 and C<-1> on failure.  The difference between
1404 C<isl_pw_qpolynomial_foreach_piece> and
1405 C<isl_pw_qpolynomial_foreach_lifted_piece> is that
1406 C<isl_pw_qpolynomial_foreach_lifted_piece> will first
1407 compute unique representations for all existentially quantified
1408 variables and then turn these existentially quantified variables
1409 into extra set variables, adapting the associated quasipolynomial
1410 accordingly.  This means that the C<set> passed to C<fn>
1411 will not have any existentially quantified variables, but that
1412 the dimensions of the sets may be different for different
1413 invocations of C<fn>.
1415 To iterate over all terms in a quasipolynomial,
1418         int isl_qpolynomial_foreach_term(
1419                 __isl_keep isl_qpolynomial *qp,
1420                 int (*fn)(__isl_take isl_term *term,
1421                           void *user), void *user);
1423 The terms themselves can be inspected and freed using
1424 these functions
1426         unsigned isl_term_dim(__isl_keep isl_term *term,
1427                 enum isl_dim_type type);
1428         void isl_term_get_num(__isl_keep isl_term *term,
1429                 isl_int *n);
1430         void isl_term_get_den(__isl_keep isl_term *term,
1431                 isl_int *d);
1432         int isl_term_get_exp(__isl_keep isl_term *term,
1433                 enum isl_dim_type type, unsigned pos);
1434         __isl_give isl_div *isl_term_get_div(
1435                 __isl_keep isl_term *term, unsigned pos);
1436         void isl_term_free(__isl_take isl_term *term);
1438 Each term is a product of parameters, set variables and
1439 integer divisions.  The function C<isl_term_get_exp>
1440 returns the exponent of a given dimensions in the given term.
1441 The C<isl_int>s in the arguments of C<isl_term_get_num>
1442 and C<isl_term_get_den> need to have been initialized
1443 using C<isl_int_init> before calling these functions.
1445 =head3 Properties of (Piecewise) Quasipolynomials
1447 To check whether a quasipolynomial is actually a constant,
1448 use the following function.
1450         int isl_qpolynomial_is_cst(__isl_keep isl_qpolynomial *qp,
1451                 isl_int *n, isl_int *d);
1453 If C<qp> is a constant and if C<n> and C<d> are not C<NULL>
1454 then the numerator and denominator of the constant
1455 are returned in C<*n> and C<*d>, respectively.
1457 =head3 Operations on (Piecewise) Quasipolynomials
1459         __isl_give isl_qpolynomial *isl_qpolynomial_neg(
1460                 __isl_take isl_qpolynomial *qp);
1461         __isl_give isl_qpolynomial *isl_qpolynomial_add(
1462                 __isl_take isl_qpolynomial *qp1,
1463                 __isl_take isl_qpolynomial *qp2);
1464         __isl_give isl_qpolynomial *isl_qpolynomial_sub(
1465                 __isl_take isl_qpolynomial *qp1,
1466                 __isl_take isl_qpolynomial *qp2);
1467         __isl_give isl_qpolynomial *isl_qpolynomial_mul(
1468                 __isl_take isl_qpolynomial *qp1,
1469                 __isl_take isl_qpolynomial *qp2);
1471         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add(
1472                 __isl_take isl_pw_qpolynomial *pwqp1,
1473                 __isl_take isl_pw_qpolynomial *pwqp2);
1474         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_sub(
1475                 __isl_take isl_pw_qpolynomial *pwqp1,
1476                 __isl_take isl_pw_qpolynomial *pwqp2);
1477         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add_disjoint(
1478                 __isl_take isl_pw_qpolynomial *pwqp1,
1479                 __isl_take isl_pw_qpolynomial *pwqp2);
1480         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_neg(
1481                 __isl_take isl_pw_qpolynomial *pwqp);
1482         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_mul(
1483                 __isl_take isl_pw_qpolynomial *pwqp1,
1484                 __isl_take isl_pw_qpolynomial *pwqp2);
1486         __isl_give isl_qpolynomial *isl_pw_qpolynomial_eval(
1487                 __isl_take isl_pw_qpolynomial *pwqp,
1488                 __isl_take isl_point *pnt);
1490         __isl_give isl_set *isl_pw_qpolynomial_domain(
1491                 __isl_take isl_pw_qpolynomial *pwqp);
1492         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_domain(
1493                 __isl_take isl_pw_qpolynomial *pwpq,
1494                 __isl_take isl_set *set);
1496         __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_gist(
1497                 __isl_take isl_pw_qpolynomial *pwqp,
1498                 __isl_take isl_set *context);
1500 The gist operation applies the gist operation to each of
1501 the cells in the domain of the input piecewise quasipolynomial.
1502 In future, the operation will also exploit the context
1503 to simplify the quasipolynomials associated to each cell.
1505 =head2 Bounds on Piecewise Quasipolynomials and Piecewise Quasipolynomial Reductions
1507 A piecewise quasipolynomial reduction is a piecewise
1508 reduction (or fold) of quasipolynomials.
1509 In particular, the reduction can be maximum or a minimum.
1510 The objects are mainly used to represent the result of
1511 an upper or lower bound on a quasipolynomial over its domain,
1512 i.e., as the result of the following function.
1514         __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_bound(
1515                 __isl_take isl_pw_qpolynomial *pwqp,
1516                 enum isl_fold type, int *tight);
1518 The C<type> argument may be either C<isl_fold_min> or C<isl_fold_max>.
1519 If C<tight> is not C<NULL>, then C<*tight> is set to C<1>
1520 is the returned bound is known be tight, i.e., for each value
1521 of the parameters there is at least
1522 one element in the domain that reaches the bound.
1524 A (piecewise) quasipolynomial reduction can be copied or freed using the
1525 following functions.
1527         __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_copy(
1528                 __isl_keep isl_qpolynomial_fold *fold);
1529         __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_copy(
1530                 __isl_keep isl_pw_qpolynomial_fold *pwf);
1531         void isl_qpolynomial_fold_free(
1532                 __isl_take isl_qpolynomial_fold *fold);
1533         void isl_pw_qpolynomial_fold_free(
1534                 __isl_take isl_pw_qpolynomial_fold *pwf);
1536 =head3 Printing Piecewise Quasipolynomial Reductions
1538 Piecewise quasipolynomial reductions can be printed
1539 using the following function.
1541         __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
1542                 __isl_take isl_printer *p,
1543                 __isl_keep isl_pw_qpolynomial_fold *pwf);
1545 The output format of the printer
1546 needs to be set to either C<ISL_FORMAT_ISL> or C<ISL_FORMAT_C>.
1548 =head3 Inspecting (Piecewise) Quasipolynomial Reductions
1550 To iterate over the cells in a piecewise quasipolynomial reduction,
1551 use either of the following two functions
1553         int isl_pw_qpolynomial_fold_foreach_piece(
1554                 __isl_keep isl_pw_qpolynomial_fold *pwf,
1555                 int (*fn)(__isl_take isl_set *set,
1556                           __isl_take isl_qpolynomial_fold *fold,
1557                           void *user), void *user);
1558         int isl_pw_qpolynomial_fold_foreach_lifted_piece(
1559                 __isl_keep isl_pw_qpolynomial_fold *pwf,
1560                 int (*fn)(__isl_take isl_set *set,
1561                           __isl_take isl_qpolynomial_fold *fold,
1562                           void *user), void *user);
1564 See L<Inspecting (Piecewise) Quasipolynomials> for an explanation
1565 of the difference between these two functions.
1567 To iterate over all quasipolynomials in a reduction, use
1569         int isl_qpolynomial_fold_foreach_qpolynomial(
1570                 __isl_keep isl_qpolynomial_fold *fold,
1571                 int (*fn)(__isl_take isl_qpolynomial *qp,
1572                           void *user), void *user);
1574 =head3 Operations on Piecewise Quasipolynomial Reductions
1576         __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_add(
1577                 __isl_take isl_pw_qpolynomial_fold *pwf1,
1578                 __isl_take isl_pw_qpolynomial_fold *pwf2);
1580         __isl_give isl_qpolynomial *isl_pw_qpolynomial_fold_eval(
1581                 __isl_take isl_pw_qpolynomial_fold *pwf,
1582                 __isl_take isl_point *pnt);
1584         __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_coalesce(
1585                 __isl_take isl_pw_qpolynomial_fold *pwf);
1587         __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_gist(
1588                 __isl_take isl_pw_qpolynomial_fold *pwf,
1589                 __isl_take isl_set *context);
1591 The gist operation applies the gist operation to each of
1592 the cells in the domain of the input piecewise quasipolynomial reduction.
1593 In future, the operation will also exploit the context
1594 to simplify the quasipolynomial reductions associated to each cell.
1596 =head2 Dependence Analysis
1598 C<isl> contains specialized functionality for performing
1599 array dataflow analysis.  That is, given a I<sink> access relation
1600 and a collection of possible I<source> access relations,
1601 C<isl> can compute relations that describe
1602 for each iteration of the sink access, which iteration
1603 of which of the source access relations was the last
1604 to access the same data element before the given iteration
1605 of the sink access.
1606 To compute standard flow dependences, the sink should be
1607 a read, while the sources should be writes.
1608 If any of the source accesses are marked as being I<may>
1609 accesses, then there will be a dependence to the last
1610 I<must> access B<and> to any I<may> access that follows
1611 this last I<must> access.
1612 In particular, if I<all> sources are I<may> accesses,
1613 then memory based dependence analysis is performed.
1614 If, on the other hand, all sources are I<must> accesses,
1615 then value based dependence analysis is performed.
1617         #include <isl_flow.h>
1619         __isl_give isl_access_info *isl_access_info_alloc(
1620                 __isl_take isl_map *sink,
1621                 void *sink_user, isl_access_level_before fn,
1622                 int max_source);
1623         __isl_give isl_access_info *isl_access_info_add_source(
1624                 __isl_take isl_access_info *acc,
1625                 __isl_take isl_map *source, int must,
1626                 void *source_user);
1628         __isl_give isl_flow *isl_access_info_compute_flow(
1629                 __isl_take isl_access_info *acc);
1631         int isl_flow_foreach(__isl_keep isl_flow *deps,
1632                 int (*fn)(__isl_take isl_map *dep, int must,
1633                           void *dep_user, void *user),
1634                 void *user);
1635         __isl_give isl_set *isl_flow_get_no_source(
1636                 __isl_keep isl_flow *deps, int must);
1637         void isl_flow_free(__isl_take isl_flow *deps);
1639 The function C<isl_access_info_compute_flow> performs the actual
1640 dependence analysis.  The other functions are used to construct
1641 the input for this function or to read off the output.
1643 The input is collected in an C<isl_access_info>, which can
1644 be created through a call to C<isl_access_info_alloc>.
1645 The arguments to this functions are the sink access relation
1646 C<sink>, a token C<sink_user> used to identify the sink
1647 access to the user, a callback function for specifying the
1648 relative order of source and sink accesses, and the number
1649 of source access relations that will be added.
1650 The callback function has type C<int (*)(void *first, void *second)>.
1651 The function is called with two user supplied tokens identifying
1652 either a source or the sink and it should return the shared nesting
1653 level and the relative order of the two accesses.
1654 In particular, let I<n> be the number of loops shared by
1655 the two accesses.  If C<first> precedes C<second> textually,
1656 then the function should return I<2 * n + 1>; otherwise,
1657 it should return I<2 * n>.
1658 The sources can be added to the C<isl_access_info> by performing
1659 (at most) C<max_source> calls to C<isl_access_info_add_source>.
1660 C<must> indicates whether the source is a I<must> access
1661 or a I<may> access.  Note that a multi-valued access relation
1662 should only be marked I<must> if every iteration in the domain
1663 of the relation accesses I<all> elements in its image.
1664 The C<source_user> token is again used to identify
1665 the source access.  The range of the source access relation
1666 C<source> should have the same dimension as the range
1667 of the sink access relation.
1669 The result of the dependence analysis is collected in an
1670 C<isl_flow>.  There may be elements in the domain of
1671 the sink access for which no preceding source access could be
1672 found or for which all preceding sources are I<may> accesses.
1673 The sets of these elements can be obtained through
1674 calls to C<isl_flow_get_no_source>, the first with C<must> set
1675 and the second with C<must> unset.
1676 In the case of standard flow dependence analysis,
1677 with the sink a read and the sources I<must> writes,
1678 the first set corresponds to the reads from uninitialized
1679 array elements and the second set is empty.
1680 The actual flow dependences can be extracted using
1681 C<isl_flow_foreach>.  This function will call the user-specified
1682 callback function C<fn> for each B<non-empty> dependence between
1683 a source and the sink.  The callback function is called
1684 with four arguments, the actual flow dependence relation
1685 mapping source iterations to sink iterations, a boolean that
1686 indicates whether it is a I<must> or I<may> dependence, a token
1687 identifying the source and an additional C<void *> with value
1688 equal to the third argument of the C<isl_flow_foreach> call.
1689 A dependence is marked I<must> if it originates from a I<must>
1690 source and if it is not followed by any I<may> sources.
1692 After finishing with an C<isl_flow>, the user should call
1693 C<isl_flow_free> to free all associated memory.
1695 =head2 Parametric Vertex Enumeration
1697 The parametric vertex enumeration described in this section
1698 is mainly intended to be used internally and by the C<barvinok>
1699 library.
1701         #include <isl_vertices.h>
1702         __isl_give isl_vertices *isl_basic_set_compute_vertices(
1703                 __isl_keep isl_basic_set *bset);
1705 The function C<isl_basic_set_compute_vertices> performs the
1706 actual computation of the parametric vertices and the chamber
1707 decomposition and store the result in an C<isl_vertices> object.
1708 This information can be queried by either iterating over all
1709 the vertices or iterating over all the chambers or cells
1710 and then iterating over all vertices that are active on the chamber.
1712         int isl_vertices_foreach_vertex(
1713                 __isl_keep isl_vertices *vertices,
1714                 int (*fn)(__isl_take isl_vertex *vertex, void *user),
1715                 void *user);
1717         int isl_vertices_foreach_cell(
1718                 __isl_keep isl_vertices *vertices,
1719                 int (*fn)(__isl_take isl_cell *cell, void *user),
1720                 void *user);
1721         int isl_cell_foreach_vertex(__isl_keep isl_cell *cell,
1722                 int (*fn)(__isl_take isl_vertex *vertex, void *user),
1723                 void *user);
1725 Other operations that can be performed on an C<isl_vertices> object are
1726 the following.
1728         isl_ctx *isl_vertices_get_ctx(
1729                 __isl_keep isl_vertices *vertices);
1730         int isl_vertices_get_n_vertices(
1731                 __isl_keep isl_vertices *vertices);
1732         void isl_vertices_free(__isl_take isl_vertices *vertices);
1734 Vertices can be inspected and destroyed using the following functions.
1736         isl_ctx *isl_vertex_get_ctx(__isl_keep isl_vertex *vertex);
1737         int isl_vertex_get_id(__isl_keep isl_vertex *vertex);
1738         __isl_give isl_basic_set *isl_vertex_get_domain(
1739                 __isl_keep isl_vertex *vertex);
1740         __isl_give isl_basic_set *isl_vertex_get_expr(
1741                 __isl_keep isl_vertex *vertex);
1742         void isl_vertex_free(__isl_take isl_vertex *vertex);
1744 C<isl_vertex_get_expr> returns a singleton parametric set describing
1745 the vertex, while C<isl_vertex_get_domain> returns the activity domain
1746 of the vertex.
1747 Note that C<isl_vertex_get_domain> and C<isl_vertex_get_expr> return
1748 B<rational> basic sets, so they should mainly be used for inspection
1749 and should not be mixed with integer sets.
1751 Chambers can be inspected and destroyed using the following functions.
1753         isl_ctx *isl_cell_get_ctx(__isl_keep isl_cell *cell);
1754         __isl_give isl_basic_set *isl_cell_get_domain(
1755                 __isl_keep isl_cell *cell);
1756         void isl_cell_free(__isl_take isl_cell *cell);
1758 =head1 Applications
1760 Although C<isl> is mainly meant to be used as a library,
1761 it also contains some basic applications that use some
1762 of the functionality of C<isl>.
1763 The input may be specified in either the L<isl format>
1764 or the L<PolyLib format>.
1766 =head2 C<isl_polyhedron_sample>
1768 C<isl_polyhedron_sample> takes a polyhedron as input and prints
1769 an integer element of the polyhedron, if there is any.
1770 The first column in the output is the denominator and is always
1771 equal to 1.  If the polyhedron contains no integer points,
1772 then a vector of length zero is printed.
1774 =head2 C<isl_pip>
1776 C<isl_pip> takes the same input as the C<example> program
1777 from the C<piplib> distribution, i.e., a set of constraints
1778 on the parameters, a line contains only -1 and finally a set
1779 of constraints on a parametric polyhedron.
1780 The coefficients of the parameters appear in the last columns
1781 (but before the final constant column).
1782 The output is the lexicographic minimum of the parametric polyhedron.
1783 As C<isl> currently does not have its own output format, the output
1784 is just a dump of the internal state.
1786 =head2 C<isl_polyhedron_minimize>
1788 C<isl_polyhedron_minimize> computes the minimum of some linear
1789 or affine objective function over the integer points in a polyhedron.
1790 If an affine objective function
1791 is given, then the constant should appear in the last column.
1793 =head2 C<isl_polytope_scan>
1795 Given a polytope, C<isl_polytope_scan> prints
1796 all integer points in the polytope.
1798 =head1 C<isl-polylib>
1800 The C<isl-polylib> library provides the following functions for converting
1801 between C<isl> objects and C<PolyLib> objects.
1802 The library is distributed separately for licensing reasons.
1804         #include <isl_set_polylib.h>
1805         __isl_give isl_basic_set *isl_basic_set_new_from_polylib(
1806                 Polyhedron *P, __isl_take isl_dim *dim);
1807         Polyhedron *isl_basic_set_to_polylib(
1808                 __isl_keep isl_basic_set *bset);
1809         __isl_give isl_set *isl_set_new_from_polylib(Polyhedron *D,
1810                 __isl_take isl_dim *dim);
1811         Polyhedron *isl_set_to_polylib(__isl_keep isl_set *set);
1813         #include <isl_map_polylib.h>
1814         __isl_give isl_basic_map *isl_basic_map_new_from_polylib(
1815                 Polyhedron *P, __isl_take isl_dim *dim);
1816         __isl_give isl_map *isl_map_new_from_polylib(Polyhedron *D,
1817                 __isl_take isl_dim *dim);
1818         Polyhedron *isl_basic_map_to_polylib(
1819                 __isl_keep isl_basic_map *bmap);
1820         Polyhedron *isl_map_to_polylib(__isl_keep isl_map *map);