2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
16 #include <isl_constraint.h>
17 #include <isl_polynomial.h>
21 void test_parse(struct isl_ctx *ctx)
26 str = "{ [i] -> [-i] }";
27 map = isl_map_read_from_str(ctx, str, -1);
31 str = "{ A[i] -> L[([i/3])] }";
32 map = isl_map_read_from_str(ctx, str, -1);
37 void test_read(struct isl_ctx *ctx)
39 char filename[PATH_MAX];
42 struct isl_basic_set *bset1, *bset2;
43 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
45 n = snprintf(filename, sizeof(filename),
46 "%s/test_inputs/set.omega", srcdir);
47 assert(n < sizeof(filename));
48 input = fopen(filename, "r");
51 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
52 bset2 = isl_basic_set_read_from_str(ctx, str, 0);
54 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
56 isl_basic_set_free(bset1);
57 isl_basic_set_free(bset2);
62 void test_bounded(struct isl_ctx *ctx)
67 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }", -1);
68 bounded = isl_set_is_bounded(set);
72 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }", -1);
73 bounded = isl_set_is_bounded(set);
77 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }", -1);
78 bounded = isl_set_is_bounded(set);
83 /* Construct the basic set { [i] : 5 <= i <= N } */
84 void test_construction(struct isl_ctx *ctx)
88 struct isl_basic_set *bset;
89 struct isl_constraint *c;
93 dim = isl_dim_set_alloc(ctx, 1, 1);
94 bset = isl_basic_set_universe(dim);
96 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
97 isl_int_set_si(v, -1);
98 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
100 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
101 bset = isl_basic_set_add_constraint(bset, c);
103 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
104 isl_int_set_si(v, 1);
105 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
106 isl_int_set_si(v, -5);
107 isl_constraint_set_constant(c, v);
108 bset = isl_basic_set_add_constraint(bset, c);
110 isl_basic_set_free(bset);
115 void test_dim(struct isl_ctx *ctx)
118 isl_map *map1, *map2;
120 map1 = isl_map_read_from_str(ctx,
121 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
122 map1 = isl_map_add(map1, isl_dim_in, 1);
123 map2 = isl_map_read_from_str(ctx,
124 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
125 assert(isl_map_is_equal(map1, map2));
128 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
129 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }", -1);
130 assert(isl_map_is_equal(map1, map2));
135 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
136 map1 = isl_map_read_from_str(ctx, str, -1);
137 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
138 map2 = isl_map_read_from_str(ctx, str, -1);
139 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
140 assert(isl_map_is_equal(map1, map2));
146 void test_div(struct isl_ctx *ctx)
152 struct isl_basic_set *bset;
153 struct isl_constraint *c;
158 dim = isl_dim_set_alloc(ctx, 0, 1);
159 bset = isl_basic_set_universe(dim);
161 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
162 isl_int_set_si(v, -1);
163 isl_constraint_set_constant(c, v);
164 isl_int_set_si(v, 1);
165 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
166 div = isl_div_alloc(isl_basic_set_get_dim(bset));
167 c = isl_constraint_add_div(c, div, &pos);
168 isl_int_set_si(v, 3);
169 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
170 bset = isl_basic_set_add_constraint(bset, c);
172 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
173 isl_int_set_si(v, 1);
174 isl_constraint_set_constant(c, v);
175 isl_int_set_si(v, -1);
176 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
177 div = isl_div_alloc(isl_basic_set_get_dim(bset));
178 c = isl_constraint_add_div(c, div, &pos);
179 isl_int_set_si(v, 3);
180 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
181 bset = isl_basic_set_add_constraint(bset, c);
183 assert(bset && bset->n_div == 1);
184 isl_basic_set_free(bset);
187 dim = isl_dim_set_alloc(ctx, 0, 1);
188 bset = isl_basic_set_universe(dim);
190 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
191 isl_int_set_si(v, 1);
192 isl_constraint_set_constant(c, v);
193 isl_int_set_si(v, -1);
194 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
195 div = isl_div_alloc(isl_basic_set_get_dim(bset));
196 c = isl_constraint_add_div(c, div, &pos);
197 isl_int_set_si(v, 3);
198 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
199 bset = isl_basic_set_add_constraint(bset, c);
201 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
202 isl_int_set_si(v, -1);
203 isl_constraint_set_constant(c, v);
204 isl_int_set_si(v, 1);
205 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
206 div = isl_div_alloc(isl_basic_set_get_dim(bset));
207 c = isl_constraint_add_div(c, div, &pos);
208 isl_int_set_si(v, 3);
209 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
210 bset = isl_basic_set_add_constraint(bset, c);
212 assert(bset && bset->n_div == 1);
213 isl_basic_set_free(bset);
216 dim = isl_dim_set_alloc(ctx, 0, 1);
217 bset = isl_basic_set_universe(dim);
219 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
220 isl_int_set_si(v, 1);
221 isl_constraint_set_constant(c, v);
222 isl_int_set_si(v, -1);
223 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
224 div = isl_div_alloc(isl_basic_set_get_dim(bset));
225 c = isl_constraint_add_div(c, div, &pos);
226 isl_int_set_si(v, 3);
227 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
228 bset = isl_basic_set_add_constraint(bset, c);
230 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
231 isl_int_set_si(v, -3);
232 isl_constraint_set_constant(c, v);
233 isl_int_set_si(v, 1);
234 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
235 div = isl_div_alloc(isl_basic_set_get_dim(bset));
236 c = isl_constraint_add_div(c, div, &pos);
237 isl_int_set_si(v, 4);
238 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
239 bset = isl_basic_set_add_constraint(bset, c);
241 assert(bset && bset->n_div == 1);
242 isl_basic_set_free(bset);
245 dim = isl_dim_set_alloc(ctx, 0, 1);
246 bset = isl_basic_set_universe(dim);
248 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
249 isl_int_set_si(v, 2);
250 isl_constraint_set_constant(c, v);
251 isl_int_set_si(v, -1);
252 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
253 div = isl_div_alloc(isl_basic_set_get_dim(bset));
254 c = isl_constraint_add_div(c, div, &pos);
255 isl_int_set_si(v, 3);
256 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
257 bset = isl_basic_set_add_constraint(bset, c);
259 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
260 isl_int_set_si(v, -1);
261 isl_constraint_set_constant(c, v);
262 isl_int_set_si(v, 1);
263 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
264 div = isl_div_alloc(isl_basic_set_get_dim(bset));
265 c = isl_constraint_add_div(c, div, &pos);
266 isl_int_set_si(v, 6);
267 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
268 bset = isl_basic_set_add_constraint(bset, c);
270 assert(isl_basic_set_is_empty(bset));
271 isl_basic_set_free(bset);
274 dim = isl_dim_set_alloc(ctx, 0, 2);
275 bset = isl_basic_set_universe(dim);
277 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
278 isl_int_set_si(v, -1);
279 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
280 div = isl_div_alloc(isl_basic_set_get_dim(bset));
281 c = isl_constraint_add_div(c, div, &pos);
282 isl_int_set_si(v, 3);
283 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
284 bset = isl_basic_set_add_constraint(bset, c);
286 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
287 isl_int_set_si(v, 1);
288 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
289 isl_int_set_si(v, -3);
290 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
291 bset = isl_basic_set_add_constraint(bset, c);
293 assert(bset && bset->n_div == 0);
294 isl_basic_set_free(bset);
297 dim = isl_dim_set_alloc(ctx, 0, 2);
298 bset = isl_basic_set_universe(dim);
300 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
301 isl_int_set_si(v, -1);
302 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
303 div = isl_div_alloc(isl_basic_set_get_dim(bset));
304 c = isl_constraint_add_div(c, div, &pos);
305 isl_int_set_si(v, 6);
306 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
307 bset = isl_basic_set_add_constraint(bset, c);
309 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
310 isl_int_set_si(v, 1);
311 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
312 isl_int_set_si(v, -3);
313 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
314 bset = isl_basic_set_add_constraint(bset, c);
316 assert(bset && bset->n_div == 1);
317 isl_basic_set_free(bset);
320 /* This test is a bit tricky. We set up an equality
322 * Normalization of divs creates _two_ divs
325 * Afterwards e0 is removed again because it has coefficient -1
326 * and we end up with the original equality and div again.
327 * Perhaps we can avoid the introduction of this temporary div.
329 dim = isl_dim_set_alloc(ctx, 0, 3);
330 bset = isl_basic_set_universe(dim);
332 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
333 isl_int_set_si(v, -1);
334 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
335 isl_int_set_si(v, -3);
336 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
337 isl_int_set_si(v, -3);
338 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
339 div = isl_div_alloc(isl_basic_set_get_dim(bset));
340 c = isl_constraint_add_div(c, div, &pos);
341 isl_int_set_si(v, 6);
342 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
343 bset = isl_basic_set_add_constraint(bset, c);
345 /* Test disabled for now */
347 assert(bset && bset->n_div == 1);
349 isl_basic_set_free(bset);
352 dim = isl_dim_set_alloc(ctx, 0, 4);
353 bset = isl_basic_set_universe(dim);
355 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
356 isl_int_set_si(v, -1);
357 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
358 isl_int_set_si(v, -3);
359 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
360 isl_int_set_si(v, -3);
361 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
362 div = isl_div_alloc(isl_basic_set_get_dim(bset));
363 c = isl_constraint_add_div(c, div, &pos);
364 isl_int_set_si(v, 6);
365 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
366 bset = isl_basic_set_add_constraint(bset, c);
368 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
369 isl_int_set_si(v, -1);
370 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
371 isl_int_set_si(v, 1);
372 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
373 isl_int_set_si(v, 1);
374 isl_constraint_set_constant(c, v);
375 bset = isl_basic_set_add_constraint(bset, c);
377 /* Test disabled for now */
379 assert(bset && bset->n_div == 1);
381 isl_basic_set_free(bset);
384 dim = isl_dim_set_alloc(ctx, 0, 2);
385 bset = isl_basic_set_universe(dim);
387 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
388 isl_int_set_si(v, 1);
389 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
390 isl_int_set_si(v, -1);
391 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
392 div = isl_div_alloc(isl_basic_set_get_dim(bset));
393 c = isl_constraint_add_div(c, div, &pos);
394 isl_int_set_si(v, -2);
395 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
396 bset = isl_basic_set_add_constraint(bset, c);
398 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
399 isl_int_set_si(v, -1);
400 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
401 div = isl_div_alloc(isl_basic_set_get_dim(bset));
402 c = isl_constraint_add_div(c, div, &pos);
403 isl_int_set_si(v, 3);
404 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
405 isl_int_set_si(v, 2);
406 isl_constraint_set_constant(c, v);
407 bset = isl_basic_set_add_constraint(bset, c);
409 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
411 assert(!isl_basic_set_is_empty(bset));
413 isl_basic_set_free(bset);
416 dim = isl_dim_set_alloc(ctx, 0, 2);
417 bset = isl_basic_set_universe(dim);
419 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
420 isl_int_set_si(v, 1);
421 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
422 div = isl_div_alloc(isl_basic_set_get_dim(bset));
423 c = isl_constraint_add_div(c, div, &pos);
424 isl_int_set_si(v, -2);
425 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
426 bset = isl_basic_set_add_constraint(bset, c);
428 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
430 isl_basic_set_free(bset);
435 void test_application_case(struct isl_ctx *ctx, const char *name)
437 char filename[PATH_MAX];
440 struct isl_basic_set *bset1, *bset2;
441 struct isl_basic_map *bmap;
443 n = snprintf(filename, sizeof(filename),
444 "%s/test_inputs/%s.omega", srcdir, name);
445 assert(n < sizeof(filename));
446 input = fopen(filename, "r");
449 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
450 bmap = isl_basic_map_read_from_file(ctx, input, 0);
452 bset1 = isl_basic_set_apply(bset1, bmap);
454 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
456 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
458 isl_basic_set_free(bset1);
459 isl_basic_set_free(bset2);
464 void test_application(struct isl_ctx *ctx)
466 test_application_case(ctx, "application");
467 test_application_case(ctx, "application2");
470 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
472 char filename[PATH_MAX];
475 struct isl_basic_set *bset1, *bset2;
477 n = snprintf(filename, sizeof(filename),
478 "%s/test_inputs/%s.polylib", srcdir, name);
479 assert(n < sizeof(filename));
480 input = fopen(filename, "r");
483 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
484 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
486 bset1 = isl_basic_set_affine_hull(bset1);
488 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
490 isl_basic_set_free(bset1);
491 isl_basic_set_free(bset2);
496 void test_affine_hull(struct isl_ctx *ctx)
498 test_affine_hull_case(ctx, "affine2");
499 test_affine_hull_case(ctx, "affine");
500 test_affine_hull_case(ctx, "affine3");
503 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
505 char filename[PATH_MAX];
508 struct isl_basic_set *bset1, *bset2;
511 n = snprintf(filename, sizeof(filename),
512 "%s/test_inputs/%s.polylib", srcdir, name);
513 assert(n < sizeof(filename));
514 input = fopen(filename, "r");
517 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
518 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
520 set = isl_basic_set_union(bset1, bset2);
521 bset1 = isl_set_convex_hull(set);
523 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
525 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
527 isl_basic_set_free(bset1);
528 isl_basic_set_free(bset2);
533 void test_convex_hull(struct isl_ctx *ctx)
535 const char *str1, *str2;
536 isl_set *set1, *set2;
538 test_convex_hull_case(ctx, "convex0");
539 test_convex_hull_case(ctx, "convex1");
540 test_convex_hull_case(ctx, "convex2");
541 test_convex_hull_case(ctx, "convex3");
542 test_convex_hull_case(ctx, "convex4");
543 test_convex_hull_case(ctx, "convex5");
544 test_convex_hull_case(ctx, "convex6");
545 test_convex_hull_case(ctx, "convex7");
546 test_convex_hull_case(ctx, "convex8");
547 test_convex_hull_case(ctx, "convex9");
548 test_convex_hull_case(ctx, "convex10");
549 test_convex_hull_case(ctx, "convex11");
550 test_convex_hull_case(ctx, "convex12");
551 test_convex_hull_case(ctx, "convex13");
552 test_convex_hull_case(ctx, "convex14");
553 test_convex_hull_case(ctx, "convex15");
555 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
556 "(i0 = 1 and i1 = 0 and i2 = 1) or "
557 "(i0 = 0 and i1 = 0 and i2 = 0) }";
558 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
559 set1 = isl_set_read_from_str(ctx, str1, -1);
560 set2 = isl_set_read_from_str(ctx, str2, -1);
561 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
562 assert(isl_set_is_equal(set1, set2));
567 void test_gist_case(struct isl_ctx *ctx, const char *name)
569 char filename[PATH_MAX];
572 struct isl_basic_set *bset1, *bset2;
574 n = snprintf(filename, sizeof(filename),
575 "%s/test_inputs/%s.polylib", srcdir, name);
576 assert(n < sizeof(filename));
577 input = fopen(filename, "r");
580 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
581 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
583 bset1 = isl_basic_set_gist(bset1, bset2);
585 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
587 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
589 isl_basic_set_free(bset1);
590 isl_basic_set_free(bset2);
595 void test_gist(struct isl_ctx *ctx)
597 test_gist_case(ctx, "gist1");
600 void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
604 set = isl_set_read_from_str(ctx, str, -1);
605 set = isl_set_coalesce(set);
606 set2 = isl_set_read_from_str(ctx, str, -1);
607 assert(isl_set_is_equal(set, set2));
609 assert(set && set->n == 1);
614 void test_coalesce(struct isl_ctx *ctx)
617 struct isl_set *set, *set2;
618 struct isl_map *map, *map2;
620 set = isl_set_read_from_str(ctx,
621 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
622 "y >= x & x >= 2 & 5 >= y }", -1);
623 set = isl_set_coalesce(set);
624 assert(set && set->n == 1);
627 set = isl_set_read_from_str(ctx,
628 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
629 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
630 set = isl_set_coalesce(set);
631 assert(set && set->n == 1);
634 set = isl_set_read_from_str(ctx,
635 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
636 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
637 set = isl_set_coalesce(set);
638 assert(set && set->n == 2);
641 set = isl_set_read_from_str(ctx,
642 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
643 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
644 set = isl_set_coalesce(set);
645 assert(set && set->n == 1);
648 set = isl_set_read_from_str(ctx,
649 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
650 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
651 set = isl_set_coalesce(set);
652 assert(set && set->n == 2);
655 set = isl_set_read_from_str(ctx,
656 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
657 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
658 set = isl_set_coalesce(set);
659 assert(set && set->n == 2);
662 set = isl_set_read_from_str(ctx,
663 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
664 "y >= 0 & x = 6 & y <= 6}", -1);
665 set = isl_set_coalesce(set);
666 assert(set && set->n == 1);
669 set = isl_set_read_from_str(ctx,
670 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
671 "y >= 0 & x = 7 & y <= 6}", -1);
672 set = isl_set_coalesce(set);
673 assert(set && set->n == 2);
676 set = isl_set_read_from_str(ctx,
677 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
678 "y >= 0 & x = 6 & y <= 5}", -1);
679 set = isl_set_coalesce(set);
680 assert(set && set->n == 1);
681 set2 = isl_set_read_from_str(ctx,
682 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
683 "y >= 0 & x = 6 & y <= 5}", -1);
684 assert(isl_set_is_equal(set, set2));
688 set = isl_set_read_from_str(ctx,
689 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
690 "y >= 0 & x = 6 & y <= 7}", -1);
691 set = isl_set_coalesce(set);
692 assert(set && set->n == 2);
695 set = isl_set_read_from_str(ctx,
696 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
697 set = isl_set_coalesce(set);
698 assert(set && set->n == 1);
699 set2 = isl_set_read_from_str(ctx,
700 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
701 assert(isl_set_is_equal(set, set2));
705 set = isl_set_read_from_str(ctx,
706 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
707 set = isl_set_coalesce(set);
708 set2 = isl_set_read_from_str(ctx,
709 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
710 assert(isl_set_is_equal(set, set2));
714 set = isl_set_read_from_str(ctx,
715 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
716 "2 <= i and i <= n }", -1);
717 set = isl_set_coalesce(set);
718 assert(set && set->n == 1);
719 set2 = isl_set_read_from_str(ctx,
720 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
721 "2 <= i and i <= n }", -1);
722 assert(isl_set_is_equal(set, set2));
726 map = isl_map_read_from_str(ctx,
727 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
728 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
729 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
730 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
731 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
732 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
733 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
734 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
735 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
736 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
737 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
738 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
739 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
740 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
741 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
742 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
743 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
744 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
745 map = isl_map_coalesce(map);
746 map2 = isl_map_read_from_str(ctx,
747 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
748 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
749 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
750 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
751 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
752 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
753 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
754 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
755 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
756 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
757 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
758 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
759 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
760 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
761 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
762 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
763 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
764 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
765 assert(isl_map_is_equal(map, map2));
769 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
770 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
771 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
772 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
773 map = isl_map_read_from_str(ctx, str, -1);
774 map = isl_map_coalesce(map);
775 map2 = isl_map_read_from_str(ctx, str, -1);
776 assert(isl_map_is_equal(map, map2));
780 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
781 "[o0, o1, o2, o3, o4, o5, o6] : "
782 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
783 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
784 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
785 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
786 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
787 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
788 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
789 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
790 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
791 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
792 "o6 >= i3 + i6 - o3 and M >= 0 and "
793 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
794 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
795 map = isl_map_read_from_str(ctx, str, -1);
796 map = isl_map_coalesce(map);
797 map2 = isl_map_read_from_str(ctx, str, -1);
798 assert(isl_map_is_equal(map, map2));
802 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
803 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
804 "(o0 = 0 and M >= 2 and N >= 3) or "
805 "(M = 0 and o0 = 0 and N >= 3) }";
806 map = isl_map_read_from_str(ctx, str, -1);
807 map = isl_map_coalesce(map);
808 map2 = isl_map_read_from_str(ctx, str, -1);
809 assert(isl_map_is_equal(map, map2));
813 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
814 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
815 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
816 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
817 map = isl_map_read_from_str(ctx, str, -1);
818 map = isl_map_coalesce(map);
819 map2 = isl_map_read_from_str(ctx, str, -1);
820 assert(isl_map_is_equal(map, map2));
824 test_coalesce_set(ctx,
825 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
826 "(i1 = M and M >= 1) }", 0);
827 test_coalesce_set(ctx,
828 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
829 test_coalesce_set(ctx,
830 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
831 "(y = 3 and x = 1) }", 1);
832 test_coalesce_set(ctx,
833 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
834 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
835 "i1 <= M and i3 <= M and i4 <= M) or "
836 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
837 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
838 "i4 <= -1 + M) }", 1);
839 test_coalesce_set(ctx,
840 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
841 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
842 test_coalesce_set(ctx,
843 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
844 "-x - y + 1 >= 0 and -3 <= z <= 3;"
845 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
846 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
847 test_coalesce_set(ctx,
848 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
851 void test_closure(struct isl_ctx *ctx)
859 /* COCOA example 1 */
860 map = isl_map_read_from_str(ctx,
861 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
862 "1 <= i and i < n and 1 <= j and j < n or "
863 "i2 = i + 1 and j2 = j - 1 and "
864 "1 <= i and i < n and 2 <= j and j <= n }", -1);
865 map = isl_map_power(map, 1, &exact);
869 /* COCOA example 1 */
870 map = isl_map_read_from_str(ctx,
871 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
872 "1 <= i and i < n and 1 <= j and j < n or "
873 "i2 = i + 1 and j2 = j - 1 and "
874 "1 <= i and i < n and 2 <= j and j <= n }", -1);
875 map = isl_map_transitive_closure(map, &exact);
877 map2 = isl_map_read_from_str(ctx,
878 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
879 "1 <= i and i < n and 1 <= j and j <= n and "
880 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
881 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
882 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
883 assert(isl_map_is_equal(map, map2));
887 map = isl_map_read_from_str(ctx,
888 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
889 " 0 <= y and y <= n }", -1);
890 map = isl_map_transitive_closure(map, &exact);
891 map2 = isl_map_read_from_str(ctx,
892 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
893 " 0 <= y and y <= n }", -1);
894 assert(isl_map_is_equal(map, map2));
898 /* COCOA example 2 */
899 map = isl_map_read_from_str(ctx,
900 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
901 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
902 "i2 = i + 2 and j2 = j - 2 and "
903 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
904 map = isl_map_transitive_closure(map, &exact);
906 map2 = isl_map_read_from_str(ctx,
907 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
908 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
909 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
910 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
911 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
912 assert(isl_map_is_equal(map, map2));
916 /* COCOA Fig.2 left */
917 map = isl_map_read_from_str(ctx,
918 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
919 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
921 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
922 "j <= 2 i - 3 and j <= n - 2 or "
923 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
924 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
925 map = isl_map_transitive_closure(map, &exact);
929 /* COCOA Fig.2 right */
930 map = isl_map_read_from_str(ctx,
931 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
932 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
934 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
935 "j <= 2 i - 4 and j <= n - 3 or "
936 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
937 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
938 map = isl_map_power(map, 1, &exact);
942 /* COCOA Fig.2 right */
943 map = isl_map_read_from_str(ctx,
944 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
945 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
947 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
948 "j <= 2 i - 4 and j <= n - 3 or "
949 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
950 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
951 map = isl_map_transitive_closure(map, &exact);
953 map2 = isl_map_read_from_str(ctx,
954 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
955 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
956 "j <= n and 3 + i + 2 j <= 3 n and "
957 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
958 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
959 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
960 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
961 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
962 assert(isl_map_is_equal(map, map2));
966 /* COCOA Fig.1 right */
967 dom = isl_set_read_from_str(ctx,
968 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
969 "2 x - 3 y + 3 >= 0 }", -1);
970 right = isl_map_read_from_str(ctx,
971 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
972 up = isl_map_read_from_str(ctx,
973 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
974 right = isl_map_intersect_domain(right, isl_set_copy(dom));
975 right = isl_map_intersect_range(right, isl_set_copy(dom));
976 up = isl_map_intersect_domain(up, isl_set_copy(dom));
977 up = isl_map_intersect_range(up, dom);
978 map = isl_map_union(up, right);
979 map = isl_map_transitive_closure(map, &exact);
981 map2 = isl_map_read_from_str(ctx,
982 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
983 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
984 assert(isl_map_is_equal(map, map2));
988 /* COCOA Theorem 1 counter example */
989 map = isl_map_read_from_str(ctx,
990 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
991 "i2 = 1 and j2 = j or "
992 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
993 map = isl_map_transitive_closure(map, &exact);
997 map = isl_map_read_from_str(ctx,
998 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
999 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1000 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1001 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1002 map = isl_map_transitive_closure(map, &exact);
1006 /* Kelly et al 1996, fig 12 */
1007 map = isl_map_read_from_str(ctx,
1008 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1009 "1 <= i,j,j+1 <= n or "
1010 "j = n and j2 = 1 and i2 = i + 1 and "
1011 "1 <= i,i+1 <= n }", -1);
1012 map = isl_map_transitive_closure(map, &exact);
1014 map2 = isl_map_read_from_str(ctx,
1015 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1016 "1 <= i <= n and i = i2 or "
1017 "1 <= i < i2 <= n and 1 <= j <= n and "
1018 "1 <= j2 <= n }", -1);
1019 assert(isl_map_is_equal(map, map2));
1023 /* Omega's closure4 */
1024 map = isl_map_read_from_str(ctx,
1025 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1026 "1 <= x,y <= 10 or "
1027 "x2 = x + 1 and y2 = y and "
1028 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1029 map = isl_map_transitive_closure(map, &exact);
1033 map = isl_map_read_from_str(ctx,
1034 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1035 map = isl_map_transitive_closure(map, &exact);
1037 map2 = isl_map_read_from_str(ctx,
1038 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1039 assert(isl_map_is_equal(map, map2));
1043 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1044 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1045 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1046 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1047 map = isl_map_read_from_str(ctx, str, -1);
1048 map = isl_map_transitive_closure(map, &exact);
1050 map2 = isl_map_read_from_str(ctx, str, -1);
1051 assert(isl_map_is_equal(map, map2));
1055 str = "{[0] -> [1]; [2] -> [3]}";
1056 map = isl_map_read_from_str(ctx, str, -1);
1057 map = isl_map_transitive_closure(map, &exact);
1059 map2 = isl_map_read_from_str(ctx, str, -1);
1060 assert(isl_map_is_equal(map, map2));
1065 void test_lex(struct isl_ctx *ctx)
1070 dim = isl_dim_alloc(ctx, 0, 0, 0);
1071 map = isl_map_lex_le(dim);
1072 assert(!isl_map_is_empty(map));
1076 void test_lexmin(struct isl_ctx *ctx)
1083 str = "[p0, p1] -> { [] -> [] : "
1084 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1085 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1086 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1087 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1088 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1089 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1090 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1091 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1092 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1093 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1094 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1095 map = isl_map_read_from_str(ctx, str, -1);
1096 map = isl_map_lexmin(map);
1099 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1100 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1101 set = isl_set_read_from_str(ctx, str, -1);
1102 set = isl_set_lexmax(set);
1103 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1104 set2 = isl_set_read_from_str(ctx, str, -1);
1105 set = isl_set_intersect(set, set2);
1106 assert(!isl_set_is_empty(set));
1115 static int collect_must_may(__isl_take isl_map *dep, int must,
1116 void *dep_user, void *user)
1118 struct must_may *mm = (struct must_may *)user;
1121 mm->must = isl_map_union(mm->must, dep);
1123 mm->may = isl_map_union(mm->may, dep);
1128 static int common_space(void *first, void *second)
1130 int depth = *(int *)first;
1134 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1142 map2 = isl_map_read_from_str(map->ctx, str, -1);
1143 equal = isl_map_is_equal(map, map2);
1149 void test_dep(struct isl_ctx *ctx)
1154 isl_access_info *ai;
1161 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1162 map = isl_map_read_from_str(ctx, str, -1);
1163 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1165 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1166 map = isl_map_read_from_str(ctx, str, -1);
1167 ai = isl_access_info_add_source(ai, map, 1, &depth);
1169 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1170 map = isl_map_read_from_str(ctx, str, -1);
1171 ai = isl_access_info_add_source(ai, map, 1, &depth);
1173 flow = isl_access_info_compute_flow(ai);
1174 dim = isl_dim_alloc(ctx, 0, 3, 3);
1175 mm.must = isl_map_empty(isl_dim_copy(dim));
1176 mm.may = isl_map_empty(dim);
1178 isl_flow_foreach(flow, collect_must_may, &mm);
1180 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1181 " [1,10,0] -> [2,5,0] }";
1182 assert(map_is_equal(mm.must, str));
1183 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1184 assert(map_is_equal(mm.may, str));
1186 isl_map_free(mm.must);
1187 isl_map_free(mm.may);
1188 isl_flow_free(flow);
1191 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1192 map = isl_map_read_from_str(ctx, str, -1);
1193 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1195 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1196 map = isl_map_read_from_str(ctx, str, -1);
1197 ai = isl_access_info_add_source(ai, map, 1, &depth);
1199 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1200 map = isl_map_read_from_str(ctx, str, -1);
1201 ai = isl_access_info_add_source(ai, map, 0, &depth);
1203 flow = isl_access_info_compute_flow(ai);
1204 dim = isl_dim_alloc(ctx, 0, 3, 3);
1205 mm.must = isl_map_empty(isl_dim_copy(dim));
1206 mm.may = isl_map_empty(dim);
1208 isl_flow_foreach(flow, collect_must_may, &mm);
1210 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1211 assert(map_is_equal(mm.must, str));
1212 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1213 assert(map_is_equal(mm.may, str));
1215 isl_map_free(mm.must);
1216 isl_map_free(mm.may);
1217 isl_flow_free(flow);
1220 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1221 map = isl_map_read_from_str(ctx, str, -1);
1222 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1224 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1225 map = isl_map_read_from_str(ctx, str, -1);
1226 ai = isl_access_info_add_source(ai, map, 0, &depth);
1228 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1229 map = isl_map_read_from_str(ctx, str, -1);
1230 ai = isl_access_info_add_source(ai, map, 0, &depth);
1232 flow = isl_access_info_compute_flow(ai);
1233 dim = isl_dim_alloc(ctx, 0, 3, 3);
1234 mm.must = isl_map_empty(isl_dim_copy(dim));
1235 mm.may = isl_map_empty(dim);
1237 isl_flow_foreach(flow, collect_must_may, &mm);
1239 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1240 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1241 assert(map_is_equal(mm.may, str));
1242 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1243 assert(map_is_equal(mm.must, str));
1245 isl_map_free(mm.must);
1246 isl_map_free(mm.may);
1247 isl_flow_free(flow);
1250 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1251 map = isl_map_read_from_str(ctx, str, -1);
1252 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1254 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1255 map = isl_map_read_from_str(ctx, str, -1);
1256 ai = isl_access_info_add_source(ai, map, 0, &depth);
1258 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1259 map = isl_map_read_from_str(ctx, str, -1);
1260 ai = isl_access_info_add_source(ai, map, 0, &depth);
1262 flow = isl_access_info_compute_flow(ai);
1263 dim = isl_dim_alloc(ctx, 0, 3, 3);
1264 mm.must = isl_map_empty(isl_dim_copy(dim));
1265 mm.may = isl_map_empty(dim);
1267 isl_flow_foreach(flow, collect_must_may, &mm);
1269 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1270 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1271 assert(map_is_equal(mm.may, str));
1272 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1273 assert(map_is_equal(mm.must, str));
1275 isl_map_free(mm.must);
1276 isl_map_free(mm.may);
1277 isl_flow_free(flow);
1280 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1281 map = isl_map_read_from_str(ctx, str, -1);
1282 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1284 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1285 map = isl_map_read_from_str(ctx, str, -1);
1286 ai = isl_access_info_add_source(ai, map, 0, &depth);
1288 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1289 map = isl_map_read_from_str(ctx, str, -1);
1290 ai = isl_access_info_add_source(ai, map, 0, &depth);
1292 flow = isl_access_info_compute_flow(ai);
1293 dim = isl_dim_alloc(ctx, 0, 3, 3);
1294 mm.must = isl_map_empty(isl_dim_copy(dim));
1295 mm.may = isl_map_empty(dim);
1297 isl_flow_foreach(flow, collect_must_may, &mm);
1299 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1300 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1301 assert(map_is_equal(mm.may, str));
1302 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1303 assert(map_is_equal(mm.must, str));
1305 isl_map_free(mm.must);
1306 isl_map_free(mm.may);
1307 isl_flow_free(flow);
1312 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1313 map = isl_map_read_from_str(ctx, str, -1);
1314 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1316 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1317 map = isl_map_read_from_str(ctx, str, -1);
1318 ai = isl_access_info_add_source(ai, map, 1, &depth);
1320 flow = isl_access_info_compute_flow(ai);
1321 dim = isl_dim_alloc(ctx, 0, 5, 5);
1322 mm.must = isl_map_empty(isl_dim_copy(dim));
1323 mm.may = isl_map_empty(dim);
1325 isl_flow_foreach(flow, collect_must_may, &mm);
1327 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1328 assert(map_is_equal(mm.must, str));
1329 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1330 assert(map_is_equal(mm.may, str));
1332 isl_map_free(mm.must);
1333 isl_map_free(mm.may);
1334 isl_flow_free(flow);
1337 void test_sv(struct isl_ctx *ctx)
1342 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1343 map = isl_map_read_from_str(ctx, str, -1);
1344 assert(isl_map_is_single_valued(map));
1347 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1348 map = isl_map_read_from_str(ctx, str, -1);
1349 assert(!isl_map_is_single_valued(map));
1353 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1357 map = isl_map_read_from_str(ctx, str, -1);
1359 assert(isl_map_is_bijective(map));
1361 assert(!isl_map_is_bijective(map));
1365 void test_bijective(struct isl_ctx *ctx)
1367 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1368 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1369 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1370 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1371 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1372 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1373 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1374 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1375 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1376 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1377 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1378 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1379 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1382 void test_pwqp(struct isl_ctx *ctx)
1385 isl_pw_qpolynomial *pwqp1, *pwqp2;
1387 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1388 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1390 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1393 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1394 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1396 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1398 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1400 isl_pw_qpolynomial_free(pwqp1);
1403 void test_split_periods(isl_ctx *ctx)
1406 isl_pw_qpolynomial *pwqp;
1408 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1409 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1410 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1411 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1413 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1416 isl_pw_qpolynomial_free(pwqp);
1421 struct isl_ctx *ctx;
1423 srcdir = getenv("srcdir");
1426 ctx = isl_ctx_alloc();
1427 test_split_periods(ctx);
1432 test_bijective(ctx);
1436 test_construction(ctx);
1439 test_application(ctx);
1440 test_affine_hull(ctx);
1441 test_convex_hull(ctx);