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
15 #include <isl_constraint.h>
19 void test_read(struct isl_ctx *ctx)
21 char filename[PATH_MAX];
24 struct isl_basic_set *bset1, *bset2;
25 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
27 n = snprintf(filename, sizeof(filename),
28 "%s/test_inputs/set.omega", srcdir);
29 assert(n < sizeof(filename));
30 input = fopen(filename, "r");
33 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
34 bset2 = isl_basic_set_read_from_str(ctx, str, 0);
36 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
38 isl_basic_set_free(bset1);
39 isl_basic_set_free(bset2);
44 /* Construct the basic set { [i] : 5 <= i <= N } */
45 void test_construction(struct isl_ctx *ctx)
49 struct isl_basic_set *bset;
50 struct isl_constraint *c;
54 dim = isl_dim_set_alloc(ctx, 1, 1);
55 bset = isl_basic_set_universe(dim);
57 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
58 isl_int_set_si(v, -1);
59 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
61 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
62 bset = isl_basic_set_add_constraint(bset, c);
64 c = isl_inequality_alloc(isl_dim_copy(bset->dim));
66 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
67 isl_int_set_si(v, -5);
68 isl_constraint_set_constant(c, v);
69 bset = isl_basic_set_add_constraint(bset, c);
71 isl_basic_set_free(bset);
76 void test_dim(struct isl_ctx *ctx)
80 map1 = isl_map_read_from_str(ctx,
81 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
82 map1 = isl_map_add(map1, isl_dim_in, 1);
83 map2 = isl_map_read_from_str(ctx,
84 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
85 assert(isl_map_is_equal(map1, map2));
88 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
89 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }", -1);
90 assert(isl_map_is_equal(map1, map2));
96 void test_div(struct isl_ctx *ctx)
102 struct isl_basic_set *bset;
103 struct isl_constraint *c;
108 dim = isl_dim_set_alloc(ctx, 0, 1);
109 bset = isl_basic_set_universe(dim);
111 c = isl_equality_alloc(isl_dim_copy(bset->dim));
112 isl_int_set_si(v, -1);
113 isl_constraint_set_constant(c, v);
114 isl_int_set_si(v, 1);
115 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
116 div = isl_div_alloc(isl_dim_copy(bset->dim));
117 c = isl_constraint_add_div(c, div, &pos);
118 isl_int_set_si(v, 3);
119 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
120 bset = isl_basic_set_add_constraint(bset, c);
122 c = isl_equality_alloc(isl_dim_copy(bset->dim));
123 isl_int_set_si(v, 1);
124 isl_constraint_set_constant(c, v);
125 isl_int_set_si(v, -1);
126 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
127 div = isl_div_alloc(isl_dim_copy(bset->dim));
128 c = isl_constraint_add_div(c, div, &pos);
129 isl_int_set_si(v, 3);
130 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
131 bset = isl_basic_set_add_constraint(bset, c);
133 assert(bset->n_div == 1);
134 isl_basic_set_free(bset);
137 dim = isl_dim_set_alloc(ctx, 0, 1);
138 bset = isl_basic_set_universe(dim);
140 c = isl_equality_alloc(isl_dim_copy(bset->dim));
141 isl_int_set_si(v, 1);
142 isl_constraint_set_constant(c, v);
143 isl_int_set_si(v, -1);
144 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
145 div = isl_div_alloc(isl_dim_copy(bset->dim));
146 c = isl_constraint_add_div(c, div, &pos);
147 isl_int_set_si(v, 3);
148 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
149 bset = isl_basic_set_add_constraint(bset, c);
151 c = isl_equality_alloc(isl_dim_copy(bset->dim));
152 isl_int_set_si(v, -1);
153 isl_constraint_set_constant(c, v);
154 isl_int_set_si(v, 1);
155 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
156 div = isl_div_alloc(isl_dim_copy(bset->dim));
157 c = isl_constraint_add_div(c, div, &pos);
158 isl_int_set_si(v, 3);
159 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
160 bset = isl_basic_set_add_constraint(bset, c);
162 assert(bset->n_div == 1);
163 isl_basic_set_free(bset);
166 dim = isl_dim_set_alloc(ctx, 0, 1);
167 bset = isl_basic_set_universe(dim);
169 c = isl_equality_alloc(isl_dim_copy(bset->dim));
170 isl_int_set_si(v, 1);
171 isl_constraint_set_constant(c, v);
172 isl_int_set_si(v, -1);
173 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
174 div = isl_div_alloc(isl_dim_copy(bset->dim));
175 c = isl_constraint_add_div(c, div, &pos);
176 isl_int_set_si(v, 3);
177 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
178 bset = isl_basic_set_add_constraint(bset, c);
180 c = isl_equality_alloc(isl_dim_copy(bset->dim));
181 isl_int_set_si(v, -3);
182 isl_constraint_set_constant(c, v);
183 isl_int_set_si(v, 1);
184 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
185 div = isl_div_alloc(isl_dim_copy(bset->dim));
186 c = isl_constraint_add_div(c, div, &pos);
187 isl_int_set_si(v, 4);
188 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
189 bset = isl_basic_set_add_constraint(bset, c);
191 assert(bset->n_div == 1);
192 isl_basic_set_free(bset);
195 dim = isl_dim_set_alloc(ctx, 0, 1);
196 bset = isl_basic_set_universe(dim);
198 c = isl_equality_alloc(isl_dim_copy(bset->dim));
199 isl_int_set_si(v, 2);
200 isl_constraint_set_constant(c, v);
201 isl_int_set_si(v, -1);
202 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
203 div = isl_div_alloc(isl_dim_copy(bset->dim));
204 c = isl_constraint_add_div(c, div, &pos);
205 isl_int_set_si(v, 3);
206 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
207 bset = isl_basic_set_add_constraint(bset, c);
209 c = isl_equality_alloc(isl_dim_copy(bset->dim));
210 isl_int_set_si(v, -1);
211 isl_constraint_set_constant(c, v);
212 isl_int_set_si(v, 1);
213 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
214 div = isl_div_alloc(isl_dim_copy(bset->dim));
215 c = isl_constraint_add_div(c, div, &pos);
216 isl_int_set_si(v, 6);
217 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
218 bset = isl_basic_set_add_constraint(bset, c);
220 assert(isl_basic_set_is_empty(bset));
221 isl_basic_set_free(bset);
224 dim = isl_dim_set_alloc(ctx, 0, 2);
225 bset = isl_basic_set_universe(dim);
227 c = isl_equality_alloc(isl_dim_copy(bset->dim));
228 isl_int_set_si(v, -1);
229 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
230 div = isl_div_alloc(isl_dim_copy(bset->dim));
231 c = isl_constraint_add_div(c, div, &pos);
232 isl_int_set_si(v, 3);
233 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
234 bset = isl_basic_set_add_constraint(bset, c);
236 c = isl_equality_alloc(isl_dim_copy(bset->dim));
237 isl_int_set_si(v, 1);
238 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
239 isl_int_set_si(v, -3);
240 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
241 bset = isl_basic_set_add_constraint(bset, c);
243 assert(bset->n_div == 0);
244 isl_basic_set_free(bset);
247 dim = isl_dim_set_alloc(ctx, 0, 2);
248 bset = isl_basic_set_universe(dim);
250 c = isl_equality_alloc(isl_dim_copy(bset->dim));
251 isl_int_set_si(v, -1);
252 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
253 div = isl_div_alloc(isl_dim_copy(bset->dim));
254 c = isl_constraint_add_div(c, div, &pos);
255 isl_int_set_si(v, 6);
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_dim_copy(bset->dim));
260 isl_int_set_si(v, 1);
261 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
262 isl_int_set_si(v, -3);
263 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
264 bset = isl_basic_set_add_constraint(bset, c);
266 assert(bset->n_div == 1);
267 isl_basic_set_free(bset);
270 /* This test is a bit tricky. We set up an equality
272 * Normalization of divs creates _two_ divs
275 * Afterwards e0 is removed again because it has coefficient -1
276 * and we end up with the original equality and div again.
277 * Perhaps we can avoid the introduction of this temporary div.
279 dim = isl_dim_set_alloc(ctx, 0, 3);
280 bset = isl_basic_set_universe(dim);
282 c = isl_equality_alloc(isl_dim_copy(bset->dim));
283 isl_int_set_si(v, -1);
284 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
285 isl_int_set_si(v, -3);
286 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
287 isl_int_set_si(v, -3);
288 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
289 div = isl_div_alloc(isl_dim_copy(bset->dim));
290 c = isl_constraint_add_div(c, div, &pos);
291 isl_int_set_si(v, 6);
292 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
293 bset = isl_basic_set_add_constraint(bset, c);
295 /* Test disabled for now */
297 assert(bset->n_div == 1);
299 isl_basic_set_free(bset);
302 dim = isl_dim_set_alloc(ctx, 0, 4);
303 bset = isl_basic_set_universe(dim);
305 c = isl_equality_alloc(isl_dim_copy(bset->dim));
306 isl_int_set_si(v, -1);
307 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
308 isl_int_set_si(v, -3);
309 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
310 isl_int_set_si(v, -3);
311 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
312 div = isl_div_alloc(isl_dim_copy(bset->dim));
313 c = isl_constraint_add_div(c, div, &pos);
314 isl_int_set_si(v, 6);
315 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
316 bset = isl_basic_set_add_constraint(bset, c);
318 c = isl_equality_alloc(isl_dim_copy(bset->dim));
319 isl_int_set_si(v, -1);
320 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
321 isl_int_set_si(v, 1);
322 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
323 isl_int_set_si(v, 1);
324 isl_constraint_set_constant(c, v);
325 bset = isl_basic_set_add_constraint(bset, c);
327 /* Test disabled for now */
329 assert(bset->n_div == 1);
331 isl_basic_set_free(bset);
334 dim = isl_dim_set_alloc(ctx, 0, 2);
335 bset = isl_basic_set_universe(dim);
337 c = isl_equality_alloc(isl_dim_copy(bset->dim));
338 isl_int_set_si(v, 1);
339 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
340 isl_int_set_si(v, -1);
341 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
342 div = isl_div_alloc(isl_dim_copy(bset->dim));
343 c = isl_constraint_add_div(c, div, &pos);
344 isl_int_set_si(v, -2);
345 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
346 bset = isl_basic_set_add_constraint(bset, c);
348 c = isl_equality_alloc(isl_dim_copy(bset->dim));
349 isl_int_set_si(v, -1);
350 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
351 div = isl_div_alloc(isl_dim_copy(bset->dim));
352 c = isl_constraint_add_div(c, div, &pos);
353 isl_int_set_si(v, 3);
354 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
355 isl_int_set_si(v, 2);
356 isl_constraint_set_constant(c, v);
357 bset = isl_basic_set_add_constraint(bset, c);
359 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
361 assert(!isl_basic_set_is_empty(bset));
363 isl_basic_set_free(bset);
366 dim = isl_dim_set_alloc(ctx, 0, 2);
367 bset = isl_basic_set_universe(dim);
369 c = isl_equality_alloc(isl_dim_copy(bset->dim));
370 isl_int_set_si(v, 1);
371 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
372 div = isl_div_alloc(isl_dim_copy(bset->dim));
373 c = isl_constraint_add_div(c, div, &pos);
374 isl_int_set_si(v, -2);
375 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
376 bset = isl_basic_set_add_constraint(bset, c);
378 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
380 isl_basic_set_free(bset);
385 void test_application_case(struct isl_ctx *ctx, const char *name)
387 char filename[PATH_MAX];
390 struct isl_basic_set *bset1, *bset2;
391 struct isl_basic_map *bmap;
393 n = snprintf(filename, sizeof(filename),
394 "%s/test_inputs/%s.omega", srcdir, name);
395 assert(n < sizeof(filename));
396 input = fopen(filename, "r");
399 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
400 bmap = isl_basic_map_read_from_file(ctx, input, 0);
402 bset1 = isl_basic_set_apply(bset1, bmap);
404 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
406 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
408 isl_basic_set_free(bset1);
409 isl_basic_set_free(bset2);
414 void test_application(struct isl_ctx *ctx)
416 test_application_case(ctx, "application");
417 test_application_case(ctx, "application2");
420 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
422 char filename[PATH_MAX];
425 struct isl_basic_set *bset1, *bset2;
427 n = snprintf(filename, sizeof(filename),
428 "%s/test_inputs/%s.polylib", srcdir, name);
429 assert(n < sizeof(filename));
430 input = fopen(filename, "r");
433 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
434 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
436 bset1 = isl_basic_set_affine_hull(bset1);
438 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
440 isl_basic_set_free(bset1);
441 isl_basic_set_free(bset2);
446 void test_affine_hull(struct isl_ctx *ctx)
448 test_affine_hull_case(ctx, "affine2");
449 test_affine_hull_case(ctx, "affine");
450 test_affine_hull_case(ctx, "affine3");
453 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
455 char filename[PATH_MAX];
458 struct isl_basic_set *bset1, *bset2;
461 n = snprintf(filename, sizeof(filename),
462 "%s/test_inputs/%s.polylib", srcdir, name);
463 assert(n < sizeof(filename));
464 input = fopen(filename, "r");
467 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
468 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
470 set = isl_basic_set_union(bset1, bset2);
471 bset1 = isl_set_convex_hull(set);
473 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
475 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
477 isl_basic_set_free(bset1);
478 isl_basic_set_free(bset2);
483 void test_convex_hull(struct isl_ctx *ctx)
485 test_convex_hull_case(ctx, "convex0");
486 test_convex_hull_case(ctx, "convex1");
487 test_convex_hull_case(ctx, "convex2");
488 test_convex_hull_case(ctx, "convex3");
489 test_convex_hull_case(ctx, "convex4");
490 test_convex_hull_case(ctx, "convex5");
491 test_convex_hull_case(ctx, "convex6");
492 test_convex_hull_case(ctx, "convex7");
493 test_convex_hull_case(ctx, "convex8");
494 test_convex_hull_case(ctx, "convex9");
495 test_convex_hull_case(ctx, "convex10");
496 test_convex_hull_case(ctx, "convex11");
497 test_convex_hull_case(ctx, "convex12");
498 test_convex_hull_case(ctx, "convex13");
499 test_convex_hull_case(ctx, "convex14");
500 test_convex_hull_case(ctx, "convex15");
503 void test_gist_case(struct isl_ctx *ctx, const char *name)
505 char filename[PATH_MAX];
508 struct isl_basic_set *bset1, *bset2;
510 n = snprintf(filename, sizeof(filename),
511 "%s/test_inputs/%s.polylib", srcdir, name);
512 assert(n < sizeof(filename));
513 input = fopen(filename, "r");
516 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
517 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
519 bset1 = isl_basic_set_gist(bset1, bset2);
521 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
523 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
525 isl_basic_set_free(bset1);
526 isl_basic_set_free(bset2);
531 void test_gist(struct isl_ctx *ctx)
533 test_gist_case(ctx, "gist1");
536 void test_coalesce(struct isl_ctx *ctx)
539 struct isl_set *set, *set2;
540 struct isl_map *map, *map2;
542 set = isl_set_read_from_str(ctx,
543 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
544 "y >= x & x >= 2 & 5 >= y }", -1);
545 set = isl_set_coalesce(set);
546 assert(set && set->n == 1);
549 set = isl_set_read_from_str(ctx,
550 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
551 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
552 set = isl_set_coalesce(set);
553 assert(set && set->n == 1);
556 set = isl_set_read_from_str(ctx,
557 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
558 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
559 set = isl_set_coalesce(set);
560 assert(set && set->n == 2);
563 set = isl_set_read_from_str(ctx,
564 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
565 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
566 set = isl_set_coalesce(set);
567 assert(set && set->n == 1);
570 set = isl_set_read_from_str(ctx,
571 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
572 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
573 set = isl_set_coalesce(set);
574 assert(set && set->n == 2);
577 set = isl_set_read_from_str(ctx,
578 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
579 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
580 set = isl_set_coalesce(set);
581 assert(set && set->n == 2);
584 set = isl_set_read_from_str(ctx,
585 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
586 "y >= 0 & x = 6 & y <= 6}", -1);
587 set = isl_set_coalesce(set);
588 assert(set && set->n == 1);
591 set = isl_set_read_from_str(ctx,
592 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
593 "y >= 0 & x = 7 & y <= 6}", -1);
594 set = isl_set_coalesce(set);
595 assert(set && set->n == 2);
598 set = isl_set_read_from_str(ctx,
599 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
600 "y >= 0 & x = 6 & y <= 5}", -1);
601 set = isl_set_coalesce(set);
602 assert(set && set->n == 1);
603 set2 = isl_set_read_from_str(ctx,
604 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
605 "y >= 0 & x = 6 & y <= 5}", -1);
606 assert(isl_set_is_equal(set, set2));
610 set = isl_set_read_from_str(ctx,
611 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
612 "y >= 0 & x = 6 & y <= 7}", -1);
613 set = isl_set_coalesce(set);
614 assert(set && set->n == 2);
617 set = isl_set_read_from_str(ctx,
618 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
619 set = isl_set_coalesce(set);
620 assert(set && set->n == 1);
621 set2 = isl_set_read_from_str(ctx,
622 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
623 assert(isl_set_is_equal(set, set2));
627 set = isl_set_read_from_str(ctx,
628 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
629 set = isl_set_coalesce(set);
630 set2 = isl_set_read_from_str(ctx,
631 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
632 assert(isl_set_is_equal(set, set2));
636 set = isl_set_read_from_str(ctx,
637 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
638 "2 <= i and i <= n }", -1);
639 set = isl_set_coalesce(set);
640 assert(set && set->n == 1);
641 set2 = isl_set_read_from_str(ctx,
642 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
643 "2 <= i and i <= n }", -1);
644 assert(isl_set_is_equal(set, set2));
648 map = isl_map_read_from_str(ctx,
649 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
650 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
651 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
652 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
653 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
654 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
655 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
656 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
657 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
658 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
659 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
660 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
661 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
662 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
663 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
664 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
665 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
666 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
667 map = isl_map_coalesce(map);
668 map2 = isl_map_read_from_str(ctx,
669 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
670 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
671 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
672 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
673 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
674 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
675 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
676 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
677 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
678 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
679 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
680 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
681 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
682 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
683 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
684 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
685 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
686 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
687 assert(isl_map_is_equal(map, map2));
691 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
692 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
693 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
694 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
695 map = isl_map_read_from_str(ctx, str, -1);
696 map = isl_map_coalesce(map);
697 map2 = isl_map_read_from_str(ctx, str, -1);
698 assert(isl_map_is_equal(map, map2));
702 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
703 "[o0, o1, o2, o3, o4, o5, o6] : "
704 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
705 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
706 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
707 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
708 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
709 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
710 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
711 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
712 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
713 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
714 "o6 >= i3 + i6 - o3 and M >= 0 and "
715 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
716 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
717 map = isl_map_read_from_str(ctx, str, -1);
718 map = isl_map_coalesce(map);
719 map2 = isl_map_read_from_str(ctx, str, -1);
720 assert(isl_map_is_equal(map, map2));
725 void test_closure(struct isl_ctx *ctx)
733 /* COCOA example 1 */
734 map = isl_map_read_from_str(ctx,
735 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
736 "1 <= i and i < n and 1 <= j and j < n or "
737 "i2 = i + 1 and j2 = j - 1 and "
738 "1 <= i and i < n and 2 <= j and j <= n }", -1);
739 map = isl_map_power(map, 1, &exact);
743 /* COCOA example 1 */
744 map = isl_map_read_from_str(ctx,
745 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
746 "1 <= i and i < n and 1 <= j and j < n or "
747 "i2 = i + 1 and j2 = j - 1 and "
748 "1 <= i and i < n and 2 <= j and j <= n }", -1);
749 map = isl_map_transitive_closure(map, &exact);
751 map2 = isl_map_read_from_str(ctx,
752 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
753 "1 <= i and i < n and 1 <= j and j <= n and "
754 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
755 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
756 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
757 assert(isl_map_is_equal(map, map2));
761 map = isl_map_read_from_str(ctx,
762 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
763 " 0 <= y and y <= n }", -1);
764 map = isl_map_transitive_closure(map, &exact);
765 map2 = isl_map_read_from_str(ctx,
766 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
767 " 0 <= y and y <= n }", -1);
768 assert(isl_map_is_equal(map, map2));
772 /* COCOA example 2 */
773 map = isl_map_read_from_str(ctx,
774 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
775 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
776 "i2 = i + 2 and j2 = j - 2 and "
777 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
778 map = isl_map_transitive_closure(map, &exact);
780 map2 = isl_map_read_from_str(ctx,
781 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
782 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
783 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
784 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
785 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
786 assert(isl_map_is_equal(map, map2));
790 /* COCOA Fig.2 left */
791 map = isl_map_read_from_str(ctx,
792 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
793 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
795 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
796 "j <= 2 i - 3 and j <= n - 2 or "
797 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
798 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
799 map = isl_map_transitive_closure(map, &exact);
803 /* COCOA Fig.2 right */
804 map = isl_map_read_from_str(ctx,
805 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
806 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
808 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
809 "j <= 2 i - 4 and j <= n - 3 or "
810 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
811 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
812 map = isl_map_power(map, 1, &exact);
816 /* COCOA Fig.2 right */
817 map = isl_map_read_from_str(ctx,
818 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
819 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
821 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
822 "j <= 2 i - 4 and j <= n - 3 or "
823 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
824 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
825 map = isl_map_transitive_closure(map, &exact);
827 map2 = isl_map_read_from_str(ctx,
828 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
829 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
830 "j <= n and 3 + i + 2 j <= 3 n and "
831 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
832 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
833 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
834 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
835 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
836 assert(isl_map_is_equal(map, map2));
840 /* COCOA Fig.1 right */
841 dom = isl_set_read_from_str(ctx,
842 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
843 "2 x - 3 y + 3 >= 0 }", -1);
844 right = isl_map_read_from_str(ctx,
845 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
846 up = isl_map_read_from_str(ctx,
847 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
848 right = isl_map_intersect_domain(right, isl_set_copy(dom));
849 right = isl_map_intersect_range(right, isl_set_copy(dom));
850 up = isl_map_intersect_domain(up, isl_set_copy(dom));
851 up = isl_map_intersect_range(up, dom);
852 map = isl_map_union(up, right);
853 map = isl_map_transitive_closure(map, &exact);
857 /* COCOA Theorem 1 counter example */
858 map = isl_map_read_from_str(ctx,
859 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
860 "i2 = 1 and j2 = j or "
861 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
862 map = isl_map_transitive_closure(map, &exact);
866 map = isl_map_read_from_str(ctx,
867 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
868 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
869 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
870 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
871 map = isl_map_transitive_closure(map, &exact);
875 /* Kelly et al 1996, fig 12 */
876 map = isl_map_read_from_str(ctx,
877 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
878 "1 <= i,j,j+1 <= n or "
879 "j = n and j2 = 1 and i2 = i + 1 and "
880 "1 <= i,i+1 <= n }", -1);
881 map = isl_map_transitive_closure(map, &exact);
883 map2 = isl_map_read_from_str(ctx,
884 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
885 "1 <= i <= n and i = i2 or "
886 "1 <= i < i2 <= n and 1 <= j <= n and "
887 "1 <= j2 <= n }", -1);
888 assert(isl_map_is_equal(map, map2));
892 /* Omega's closure4 */
893 map = isl_map_read_from_str(ctx,
894 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
896 "x2 = x + 1 and y2 = y and "
897 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
898 map = isl_map_transitive_closure(map, &exact);
902 map = isl_map_read_from_str(ctx,
903 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
904 map = isl_map_transitive_closure(map, &exact);
906 map2 = isl_map_read_from_str(ctx,
907 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
908 assert(isl_map_is_equal(map, map2));
912 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
913 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
914 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
915 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
916 map = isl_map_read_from_str(ctx, str, -1);
917 map = isl_map_transitive_closure(map, &exact);
919 map2 = isl_map_read_from_str(ctx, str, -1);
920 assert(isl_map_is_equal(map, map2));
929 srcdir = getenv("srcdir");
932 ctx = isl_ctx_alloc();
934 test_construction(ctx);
937 test_application(ctx);
938 test_affine_hull(ctx);
939 test_convex_hull(ctx);