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
13 #include <isl_ctx_private.h>
14 #include <isl_map_private.h>
17 #include <isl/constraint.h>
18 #include <isl/polynomial.h>
19 #include <isl/union_map.h>
20 #include <isl_factorization.h>
24 void test_parse_map(isl_ctx *ctx, const char *str)
28 map = isl_map_read_from_str(ctx, str, -1);
33 void test_parse_map_equal(isl_ctx *ctx, const char *str, const char *str2)
37 map = isl_map_read_from_str(ctx, str, -1);
38 map2 = isl_map_read_from_str(ctx, str2, -1);
39 assert(map && map2 && isl_map_is_equal(map, map2));
44 void test_parse_pwqp(isl_ctx *ctx, const char *str)
46 isl_pw_qpolynomial *pwqp;
48 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
50 isl_pw_qpolynomial_free(pwqp);
53 void test_parse(struct isl_ctx *ctx)
56 const char *str, *str2;
58 str = "{ [i] -> [-i] }";
59 map = isl_map_read_from_str(ctx, str, -1);
63 str = "{ A[i] -> L[([i/3])] }";
64 map = isl_map_read_from_str(ctx, str, -1);
68 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
69 test_parse_map(ctx, "{ [p1, y1, y2] -> [2, y1, y2] : "
70 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
72 str = "{ [x,y] : [([x/2]+y)/3] >= 1 }";
73 str2 = "{ [x, y] : 2y >= 6 - x }";
74 test_parse_map_equal(ctx, str, str2);
76 test_parse_map_equal(ctx, "{ [x,y] : x <= min(y, 2*y+3) }",
77 "{ [x,y] : x <= y, 2*y + 3 }");
78 str = "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
79 test_parse_map_equal(ctx, "{ [x,y] : x >= min(y, 2*y+3) }", str);
81 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
82 map = isl_map_read_from_str(ctx, str, -1);
83 str = "{ [new, old] -> [o0, o1] : "
84 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
85 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
86 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
87 map2 = isl_map_read_from_str(ctx, str, -1);
88 assert(isl_map_is_equal(map, map2));
92 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
93 map = isl_map_read_from_str(ctx, str, -1);
94 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
95 map2 = isl_map_read_from_str(ctx, str, -1);
96 assert(isl_map_is_equal(map, map2));
100 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
103 void test_read(struct isl_ctx *ctx)
105 char filename[PATH_MAX];
108 struct isl_basic_set *bset1, *bset2;
109 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
111 n = snprintf(filename, sizeof(filename),
112 "%s/test_inputs/set.omega", srcdir);
113 assert(n < sizeof(filename));
114 input = fopen(filename, "r");
117 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
118 bset2 = isl_basic_set_read_from_str(ctx, str, 0);
120 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
122 isl_basic_set_free(bset1);
123 isl_basic_set_free(bset2);
128 void test_bounded(struct isl_ctx *ctx)
133 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }", -1);
134 bounded = isl_set_is_bounded(set);
138 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }", -1);
139 bounded = isl_set_is_bounded(set);
143 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }", -1);
144 bounded = isl_set_is_bounded(set);
149 /* Construct the basic set { [i] : 5 <= i <= N } */
150 void test_construction(struct isl_ctx *ctx)
154 struct isl_basic_set *bset;
155 struct isl_constraint *c;
159 dim = isl_dim_set_alloc(ctx, 1, 1);
160 bset = isl_basic_set_universe(dim);
162 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
163 isl_int_set_si(v, -1);
164 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
165 isl_int_set_si(v, 1);
166 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
167 bset = isl_basic_set_add_constraint(bset, c);
169 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
170 isl_int_set_si(v, 1);
171 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
172 isl_int_set_si(v, -5);
173 isl_constraint_set_constant(c, v);
174 bset = isl_basic_set_add_constraint(bset, c);
176 isl_basic_set_free(bset);
181 void test_dim(struct isl_ctx *ctx)
184 isl_map *map1, *map2;
186 map1 = isl_map_read_from_str(ctx,
187 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
188 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
189 map2 = isl_map_read_from_str(ctx,
190 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
191 assert(isl_map_is_equal(map1, map2));
194 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
195 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }", -1);
196 assert(isl_map_is_equal(map1, map2));
201 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
202 map1 = isl_map_read_from_str(ctx, str, -1);
203 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
204 map2 = isl_map_read_from_str(ctx, str, -1);
205 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
206 assert(isl_map_is_equal(map1, map2));
212 void test_div(struct isl_ctx *ctx)
218 struct isl_basic_set *bset;
219 struct isl_constraint *c;
224 dim = isl_dim_set_alloc(ctx, 0, 1);
225 bset = isl_basic_set_universe(dim);
227 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
228 isl_int_set_si(v, -1);
229 isl_constraint_set_constant(c, v);
230 isl_int_set_si(v, 1);
231 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
232 div = isl_div_alloc(isl_basic_set_get_dim(bset));
233 c = isl_constraint_add_div(c, div, &pos);
234 isl_int_set_si(v, 3);
235 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
236 bset = isl_basic_set_add_constraint(bset, c);
238 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
239 isl_int_set_si(v, 1);
240 isl_constraint_set_constant(c, v);
241 isl_int_set_si(v, -1);
242 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
243 div = isl_div_alloc(isl_basic_set_get_dim(bset));
244 c = isl_constraint_add_div(c, div, &pos);
245 isl_int_set_si(v, 3);
246 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
247 bset = isl_basic_set_add_constraint(bset, c);
249 assert(bset && bset->n_div == 1);
250 isl_basic_set_free(bset);
253 dim = isl_dim_set_alloc(ctx, 0, 1);
254 bset = isl_basic_set_universe(dim);
256 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
257 isl_int_set_si(v, 1);
258 isl_constraint_set_constant(c, v);
259 isl_int_set_si(v, -1);
260 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
261 div = isl_div_alloc(isl_basic_set_get_dim(bset));
262 c = isl_constraint_add_div(c, div, &pos);
263 isl_int_set_si(v, 3);
264 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
265 bset = isl_basic_set_add_constraint(bset, c);
267 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
268 isl_int_set_si(v, -1);
269 isl_constraint_set_constant(c, v);
270 isl_int_set_si(v, 1);
271 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
272 div = isl_div_alloc(isl_basic_set_get_dim(bset));
273 c = isl_constraint_add_div(c, div, &pos);
274 isl_int_set_si(v, 3);
275 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
276 bset = isl_basic_set_add_constraint(bset, c);
278 assert(bset && bset->n_div == 1);
279 isl_basic_set_free(bset);
282 dim = isl_dim_set_alloc(ctx, 0, 1);
283 bset = isl_basic_set_universe(dim);
285 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
286 isl_int_set_si(v, 1);
287 isl_constraint_set_constant(c, v);
288 isl_int_set_si(v, -1);
289 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
290 div = isl_div_alloc(isl_basic_set_get_dim(bset));
291 c = isl_constraint_add_div(c, div, &pos);
292 isl_int_set_si(v, 3);
293 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
294 bset = isl_basic_set_add_constraint(bset, c);
296 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
297 isl_int_set_si(v, -3);
298 isl_constraint_set_constant(c, v);
299 isl_int_set_si(v, 1);
300 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
301 div = isl_div_alloc(isl_basic_set_get_dim(bset));
302 c = isl_constraint_add_div(c, div, &pos);
303 isl_int_set_si(v, 4);
304 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
305 bset = isl_basic_set_add_constraint(bset, c);
307 assert(bset && bset->n_div == 1);
308 isl_basic_set_free(bset);
311 dim = isl_dim_set_alloc(ctx, 0, 1);
312 bset = isl_basic_set_universe(dim);
314 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
315 isl_int_set_si(v, 2);
316 isl_constraint_set_constant(c, v);
317 isl_int_set_si(v, -1);
318 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
319 div = isl_div_alloc(isl_basic_set_get_dim(bset));
320 c = isl_constraint_add_div(c, div, &pos);
321 isl_int_set_si(v, 3);
322 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
323 bset = isl_basic_set_add_constraint(bset, c);
325 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
326 isl_int_set_si(v, -1);
327 isl_constraint_set_constant(c, v);
328 isl_int_set_si(v, 1);
329 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
330 div = isl_div_alloc(isl_basic_set_get_dim(bset));
331 c = isl_constraint_add_div(c, div, &pos);
332 isl_int_set_si(v, 6);
333 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
334 bset = isl_basic_set_add_constraint(bset, c);
336 assert(isl_basic_set_is_empty(bset));
337 isl_basic_set_free(bset);
340 dim = isl_dim_set_alloc(ctx, 0, 2);
341 bset = isl_basic_set_universe(dim);
343 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
344 isl_int_set_si(v, -1);
345 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
346 div = isl_div_alloc(isl_basic_set_get_dim(bset));
347 c = isl_constraint_add_div(c, div, &pos);
348 isl_int_set_si(v, 3);
349 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
350 bset = isl_basic_set_add_constraint(bset, c);
352 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
353 isl_int_set_si(v, 1);
354 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
355 isl_int_set_si(v, -3);
356 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
357 bset = isl_basic_set_add_constraint(bset, c);
359 assert(bset && bset->n_div == 0);
360 isl_basic_set_free(bset);
363 dim = isl_dim_set_alloc(ctx, 0, 2);
364 bset = isl_basic_set_universe(dim);
366 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
367 isl_int_set_si(v, -1);
368 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
369 div = isl_div_alloc(isl_basic_set_get_dim(bset));
370 c = isl_constraint_add_div(c, div, &pos);
371 isl_int_set_si(v, 6);
372 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
373 bset = isl_basic_set_add_constraint(bset, c);
375 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
376 isl_int_set_si(v, 1);
377 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
378 isl_int_set_si(v, -3);
379 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
380 bset = isl_basic_set_add_constraint(bset, c);
382 assert(bset && bset->n_div == 1);
383 isl_basic_set_free(bset);
386 /* This test is a bit tricky. We set up an equality
388 * Normalization of divs creates _two_ divs
391 * Afterwards e0 is removed again because it has coefficient -1
392 * and we end up with the original equality and div again.
393 * Perhaps we can avoid the introduction of this temporary div.
395 dim = isl_dim_set_alloc(ctx, 0, 3);
396 bset = isl_basic_set_universe(dim);
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 isl_int_set_si(v, -3);
402 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
403 isl_int_set_si(v, -3);
404 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
405 div = isl_div_alloc(isl_basic_set_get_dim(bset));
406 c = isl_constraint_add_div(c, div, &pos);
407 isl_int_set_si(v, 6);
408 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
409 bset = isl_basic_set_add_constraint(bset, c);
411 /* Test disabled for now */
413 assert(bset && bset->n_div == 1);
415 isl_basic_set_free(bset);
418 dim = isl_dim_set_alloc(ctx, 0, 4);
419 bset = isl_basic_set_universe(dim);
421 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
422 isl_int_set_si(v, -1);
423 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
424 isl_int_set_si(v, -3);
425 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
426 isl_int_set_si(v, -3);
427 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
428 div = isl_div_alloc(isl_basic_set_get_dim(bset));
429 c = isl_constraint_add_div(c, div, &pos);
430 isl_int_set_si(v, 6);
431 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
432 bset = isl_basic_set_add_constraint(bset, c);
434 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
435 isl_int_set_si(v, -1);
436 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
437 isl_int_set_si(v, 1);
438 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
439 isl_int_set_si(v, 1);
440 isl_constraint_set_constant(c, v);
441 bset = isl_basic_set_add_constraint(bset, c);
443 /* Test disabled for now */
445 assert(bset && bset->n_div == 1);
447 isl_basic_set_free(bset);
450 dim = isl_dim_set_alloc(ctx, 0, 2);
451 bset = isl_basic_set_universe(dim);
453 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
454 isl_int_set_si(v, 1);
455 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
456 isl_int_set_si(v, -1);
457 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
458 div = isl_div_alloc(isl_basic_set_get_dim(bset));
459 c = isl_constraint_add_div(c, div, &pos);
460 isl_int_set_si(v, -2);
461 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
462 bset = isl_basic_set_add_constraint(bset, c);
464 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
465 isl_int_set_si(v, -1);
466 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
467 div = isl_div_alloc(isl_basic_set_get_dim(bset));
468 c = isl_constraint_add_div(c, div, &pos);
469 isl_int_set_si(v, 3);
470 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
471 isl_int_set_si(v, 2);
472 isl_constraint_set_constant(c, v);
473 bset = isl_basic_set_add_constraint(bset, c);
475 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
477 assert(!isl_basic_set_is_empty(bset));
479 isl_basic_set_free(bset);
482 dim = isl_dim_set_alloc(ctx, 0, 2);
483 bset = isl_basic_set_universe(dim);
485 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
486 isl_int_set_si(v, 1);
487 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
488 div = isl_div_alloc(isl_basic_set_get_dim(bset));
489 c = isl_constraint_add_div(c, div, &pos);
490 isl_int_set_si(v, -2);
491 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
492 bset = isl_basic_set_add_constraint(bset, c);
494 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
496 isl_basic_set_free(bset);
501 void test_application_case(struct isl_ctx *ctx, const char *name)
503 char filename[PATH_MAX];
506 struct isl_basic_set *bset1, *bset2;
507 struct isl_basic_map *bmap;
509 n = snprintf(filename, sizeof(filename),
510 "%s/test_inputs/%s.omega", srcdir, name);
511 assert(n < sizeof(filename));
512 input = fopen(filename, "r");
515 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
516 bmap = isl_basic_map_read_from_file(ctx, input, 0);
518 bset1 = isl_basic_set_apply(bset1, bmap);
520 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
522 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
524 isl_basic_set_free(bset1);
525 isl_basic_set_free(bset2);
530 void test_application(struct isl_ctx *ctx)
532 test_application_case(ctx, "application");
533 test_application_case(ctx, "application2");
536 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
538 char filename[PATH_MAX];
541 struct isl_basic_set *bset1, *bset2;
543 n = snprintf(filename, sizeof(filename),
544 "%s/test_inputs/%s.polylib", srcdir, name);
545 assert(n < sizeof(filename));
546 input = fopen(filename, "r");
549 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
550 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
552 bset1 = isl_basic_set_affine_hull(bset1);
554 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
556 isl_basic_set_free(bset1);
557 isl_basic_set_free(bset2);
562 void test_affine_hull(struct isl_ctx *ctx)
564 test_affine_hull_case(ctx, "affine2");
565 test_affine_hull_case(ctx, "affine");
566 test_affine_hull_case(ctx, "affine3");
569 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
571 char filename[PATH_MAX];
574 struct isl_basic_set *bset1, *bset2;
577 n = snprintf(filename, sizeof(filename),
578 "%s/test_inputs/%s.polylib", srcdir, name);
579 assert(n < sizeof(filename));
580 input = fopen(filename, "r");
583 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
584 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
586 set = isl_basic_set_union(bset1, bset2);
587 bset1 = isl_set_convex_hull(set);
589 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
591 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
593 isl_basic_set_free(bset1);
594 isl_basic_set_free(bset2);
599 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
601 const char *str1, *str2;
602 isl_set *set1, *set2;
603 int orig_convex = ctx->opt->convex;
604 ctx->opt->convex = convex;
606 test_convex_hull_case(ctx, "convex0");
607 test_convex_hull_case(ctx, "convex1");
608 test_convex_hull_case(ctx, "convex2");
609 test_convex_hull_case(ctx, "convex3");
610 test_convex_hull_case(ctx, "convex4");
611 test_convex_hull_case(ctx, "convex5");
612 test_convex_hull_case(ctx, "convex6");
613 test_convex_hull_case(ctx, "convex7");
614 test_convex_hull_case(ctx, "convex8");
615 test_convex_hull_case(ctx, "convex9");
616 test_convex_hull_case(ctx, "convex10");
617 test_convex_hull_case(ctx, "convex11");
618 test_convex_hull_case(ctx, "convex12");
619 test_convex_hull_case(ctx, "convex13");
620 test_convex_hull_case(ctx, "convex14");
621 test_convex_hull_case(ctx, "convex15");
623 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
624 "(i0 = 1 and i1 = 0 and i2 = 1) or "
625 "(i0 = 0 and i1 = 0 and i2 = 0) }";
626 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
627 set1 = isl_set_read_from_str(ctx, str1, -1);
628 set2 = isl_set_read_from_str(ctx, str2, -1);
629 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
630 assert(isl_set_is_equal(set1, set2));
634 ctx->opt->convex = orig_convex;
637 void test_convex_hull(struct isl_ctx *ctx)
639 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
640 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
643 void test_gist_case(struct isl_ctx *ctx, const char *name)
645 char filename[PATH_MAX];
648 struct isl_basic_set *bset1, *bset2;
650 n = snprintf(filename, sizeof(filename),
651 "%s/test_inputs/%s.polylib", srcdir, name);
652 assert(n < sizeof(filename));
653 input = fopen(filename, "r");
656 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
657 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
659 bset1 = isl_basic_set_gist(bset1, bset2);
661 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
663 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
665 isl_basic_set_free(bset1);
666 isl_basic_set_free(bset2);
671 void test_gist(struct isl_ctx *ctx)
674 isl_basic_set *bset1, *bset2;
676 test_gist_case(ctx, "gist1");
678 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
679 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
680 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
681 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
682 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
683 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
684 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
685 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
686 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
687 bset1 = isl_basic_set_read_from_str(ctx, str, -1);
688 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
689 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
690 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
691 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
692 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
693 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
694 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
695 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
696 bset2 = isl_basic_set_read_from_str(ctx, str, -1);
697 bset1 = isl_basic_set_gist(bset1, bset2);
698 assert(bset1 && bset1->n_div == 0);
699 isl_basic_set_free(bset1);
702 void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
706 set = isl_set_read_from_str(ctx, str, -1);
707 set = isl_set_coalesce(set);
708 set2 = isl_set_read_from_str(ctx, str, -1);
709 assert(isl_set_is_equal(set, set2));
711 assert(set && set->n == 1);
716 void test_coalesce(struct isl_ctx *ctx)
719 struct isl_set *set, *set2;
720 struct isl_map *map, *map2;
722 set = isl_set_read_from_str(ctx,
723 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
724 "y >= x & x >= 2 & 5 >= y }", -1);
725 set = isl_set_coalesce(set);
726 assert(set && set->n == 1);
729 set = isl_set_read_from_str(ctx,
730 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
731 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
732 set = isl_set_coalesce(set);
733 assert(set && set->n == 1);
736 set = isl_set_read_from_str(ctx,
737 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
738 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
739 set = isl_set_coalesce(set);
740 assert(set && set->n == 2);
743 set = isl_set_read_from_str(ctx,
744 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
745 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
746 set = isl_set_coalesce(set);
747 assert(set && set->n == 1);
750 set = isl_set_read_from_str(ctx,
751 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
752 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
753 set = isl_set_coalesce(set);
754 assert(set && set->n == 2);
757 set = isl_set_read_from_str(ctx,
758 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
759 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
760 set = isl_set_coalesce(set);
761 assert(set && set->n == 2);
764 set = isl_set_read_from_str(ctx,
765 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
766 "y >= 0 & x = 6 & y <= 6}", -1);
767 set = isl_set_coalesce(set);
768 assert(set && set->n == 1);
771 set = isl_set_read_from_str(ctx,
772 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
773 "y >= 0 & x = 7 & y <= 6}", -1);
774 set = isl_set_coalesce(set);
775 assert(set && set->n == 2);
778 set = isl_set_read_from_str(ctx,
779 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
780 "y >= 0 & x = 6 & y <= 5}", -1);
781 set = isl_set_coalesce(set);
782 assert(set && set->n == 1);
783 set2 = isl_set_read_from_str(ctx,
784 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
785 "y >= 0 & x = 6 & y <= 5}", -1);
786 assert(isl_set_is_equal(set, set2));
790 set = isl_set_read_from_str(ctx,
791 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
792 "y >= 0 & x = 6 & y <= 7}", -1);
793 set = isl_set_coalesce(set);
794 assert(set && set->n == 2);
797 set = isl_set_read_from_str(ctx,
798 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
799 set = isl_set_coalesce(set);
800 assert(set && set->n == 1);
801 set2 = isl_set_read_from_str(ctx,
802 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
803 assert(isl_set_is_equal(set, set2));
807 set = isl_set_read_from_str(ctx,
808 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
809 set = isl_set_coalesce(set);
810 set2 = isl_set_read_from_str(ctx,
811 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
812 assert(isl_set_is_equal(set, set2));
816 set = isl_set_read_from_str(ctx,
817 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
818 "2 <= i and i <= n }", -1);
819 set = isl_set_coalesce(set);
820 assert(set && set->n == 1);
821 set2 = isl_set_read_from_str(ctx,
822 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
823 "2 <= i and i <= n }", -1);
824 assert(isl_set_is_equal(set, set2));
828 map = isl_map_read_from_str(ctx,
829 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
830 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
831 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
832 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
833 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
834 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
835 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
836 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
837 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
838 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
839 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
840 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
841 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
842 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
843 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
844 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
845 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
846 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
847 map = isl_map_coalesce(map);
848 map2 = isl_map_read_from_str(ctx,
849 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
850 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
851 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
852 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
853 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
854 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
855 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
856 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
857 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
858 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
859 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
860 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
861 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
862 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
863 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
864 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
865 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
866 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
867 assert(isl_map_is_equal(map, map2));
871 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
872 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
873 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
874 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
875 map = isl_map_read_from_str(ctx, str, -1);
876 map = isl_map_coalesce(map);
877 map2 = isl_map_read_from_str(ctx, str, -1);
878 assert(isl_map_is_equal(map, map2));
882 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
883 "[o0, o1, o2, o3, o4, o5, o6] : "
884 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
885 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
886 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
887 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
888 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
889 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
890 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
891 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
892 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
893 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
894 "o6 >= i3 + i6 - o3 and M >= 0 and "
895 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
896 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
897 map = isl_map_read_from_str(ctx, str, -1);
898 map = isl_map_coalesce(map);
899 map2 = isl_map_read_from_str(ctx, str, -1);
900 assert(isl_map_is_equal(map, map2));
904 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
905 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
906 "(o0 = 0 and M >= 2 and N >= 3) or "
907 "(M = 0 and o0 = 0 and N >= 3) }";
908 map = isl_map_read_from_str(ctx, str, -1);
909 map = isl_map_coalesce(map);
910 map2 = isl_map_read_from_str(ctx, str, -1);
911 assert(isl_map_is_equal(map, map2));
915 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
916 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
917 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
918 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
919 map = isl_map_read_from_str(ctx, str, -1);
920 map = isl_map_coalesce(map);
921 map2 = isl_map_read_from_str(ctx, str, -1);
922 assert(isl_map_is_equal(map, map2));
926 test_coalesce_set(ctx,
927 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
928 "(i1 = M and M >= 1) }", 0);
929 test_coalesce_set(ctx,
930 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
931 test_coalesce_set(ctx,
932 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
933 "(y = 3 and x = 1) }", 1);
934 test_coalesce_set(ctx,
935 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
936 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
937 "i1 <= M and i3 <= M and i4 <= M) or "
938 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
939 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
940 "i4 <= -1 + M) }", 1);
941 test_coalesce_set(ctx,
942 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
943 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
944 test_coalesce_set(ctx,
945 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
946 "-x - y + 1 >= 0 and -3 <= z <= 3;"
947 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
948 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
949 test_coalesce_set(ctx,
950 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
951 test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
952 test_coalesce_set(ctx,
953 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
954 test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
955 test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
956 test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
957 test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
958 test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
959 test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
960 test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
963 void test_closure(struct isl_ctx *ctx)
971 /* COCOA example 1 */
972 map = isl_map_read_from_str(ctx,
973 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
974 "1 <= i and i < n and 1 <= j and j < n or "
975 "i2 = i + 1 and j2 = j - 1 and "
976 "1 <= i and i < n and 2 <= j and j <= n }", -1);
977 map = isl_map_power(map, &exact);
981 /* COCOA example 1 */
982 map = isl_map_read_from_str(ctx,
983 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
984 "1 <= i and i < n and 1 <= j and j < n or "
985 "i2 = i + 1 and j2 = j - 1 and "
986 "1 <= i and i < n and 2 <= j and j <= n }", -1);
987 map = isl_map_transitive_closure(map, &exact);
989 map2 = isl_map_read_from_str(ctx,
990 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
991 "1 <= i and i < n and 1 <= j and j <= n and "
992 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
993 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
994 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
995 assert(isl_map_is_equal(map, map2));
999 map = isl_map_read_from_str(ctx,
1000 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1001 " 0 <= y and y <= n }", -1);
1002 map = isl_map_transitive_closure(map, &exact);
1003 map2 = isl_map_read_from_str(ctx,
1004 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1005 " 0 <= y and y <= n }", -1);
1006 assert(isl_map_is_equal(map, map2));
1010 /* COCOA example 2 */
1011 map = isl_map_read_from_str(ctx,
1012 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1013 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1014 "i2 = i + 2 and j2 = j - 2 and "
1015 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
1016 map = isl_map_transitive_closure(map, &exact);
1018 map2 = isl_map_read_from_str(ctx,
1019 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1020 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1021 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1022 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1023 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
1024 assert(isl_map_is_equal(map, map2));
1028 /* COCOA Fig.2 left */
1029 map = isl_map_read_from_str(ctx,
1030 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1031 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1033 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1034 "j <= 2 i - 3 and j <= n - 2 or "
1035 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1036 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1037 map = isl_map_transitive_closure(map, &exact);
1041 /* COCOA Fig.2 right */
1042 map = isl_map_read_from_str(ctx,
1043 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1044 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1046 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1047 "j <= 2 i - 4 and j <= n - 3 or "
1048 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1049 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1050 map = isl_map_power(map, &exact);
1054 /* COCOA Fig.2 right */
1055 map = isl_map_read_from_str(ctx,
1056 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1057 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1059 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1060 "j <= 2 i - 4 and j <= n - 3 or "
1061 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1062 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1063 map = isl_map_transitive_closure(map, &exact);
1065 map2 = isl_map_read_from_str(ctx,
1066 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1067 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1068 "j <= n and 3 + i + 2 j <= 3 n and "
1069 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1070 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1071 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1072 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1073 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1074 assert(isl_map_is_equal(map, map2));
1078 /* COCOA Fig.1 right */
1079 dom = isl_set_read_from_str(ctx,
1080 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1081 "2 x - 3 y + 3 >= 0 }", -1);
1082 right = isl_map_read_from_str(ctx,
1083 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1084 up = isl_map_read_from_str(ctx,
1085 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1086 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1087 right = isl_map_intersect_range(right, isl_set_copy(dom));
1088 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1089 up = isl_map_intersect_range(up, dom);
1090 map = isl_map_union(up, right);
1091 map = isl_map_transitive_closure(map, &exact);
1093 map2 = isl_map_read_from_str(ctx,
1094 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1095 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1096 assert(isl_map_is_equal(map, map2));
1100 /* COCOA Theorem 1 counter example */
1101 map = isl_map_read_from_str(ctx,
1102 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1103 "i2 = 1 and j2 = j or "
1104 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1105 map = isl_map_transitive_closure(map, &exact);
1109 map = isl_map_read_from_str(ctx,
1110 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1111 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1112 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1113 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1114 map = isl_map_transitive_closure(map, &exact);
1118 /* Kelly et al 1996, fig 12 */
1119 map = isl_map_read_from_str(ctx,
1120 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1121 "1 <= i,j,j+1 <= n or "
1122 "j = n and j2 = 1 and i2 = i + 1 and "
1123 "1 <= i,i+1 <= n }", -1);
1124 map = isl_map_transitive_closure(map, &exact);
1126 map2 = isl_map_read_from_str(ctx,
1127 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1128 "1 <= i <= n and i = i2 or "
1129 "1 <= i < i2 <= n and 1 <= j <= n and "
1130 "1 <= j2 <= n }", -1);
1131 assert(isl_map_is_equal(map, map2));
1135 /* Omega's closure4 */
1136 map = isl_map_read_from_str(ctx,
1137 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1138 "1 <= x,y <= 10 or "
1139 "x2 = x + 1 and y2 = y and "
1140 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1141 map = isl_map_transitive_closure(map, &exact);
1145 map = isl_map_read_from_str(ctx,
1146 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1147 map = isl_map_transitive_closure(map, &exact);
1149 map2 = isl_map_read_from_str(ctx,
1150 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1151 assert(isl_map_is_equal(map, map2));
1155 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1156 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1157 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1158 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1159 map = isl_map_read_from_str(ctx, str, -1);
1160 map = isl_map_transitive_closure(map, &exact);
1162 map2 = isl_map_read_from_str(ctx, str, -1);
1163 assert(isl_map_is_equal(map, map2));
1167 str = "{[0] -> [1]; [2] -> [3]}";
1168 map = isl_map_read_from_str(ctx, str, -1);
1169 map = isl_map_transitive_closure(map, &exact);
1171 map2 = isl_map_read_from_str(ctx, str, -1);
1172 assert(isl_map_is_equal(map, map2));
1176 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1177 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1178 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1179 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1180 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1181 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1182 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1183 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1184 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1185 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1186 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1187 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1188 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1189 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1190 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1191 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1192 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1193 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1194 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1195 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1196 map = isl_map_read_from_str(ctx, str, -1);
1197 map = isl_map_transitive_closure(map, NULL);
1202 void test_lex(struct isl_ctx *ctx)
1207 dim = isl_dim_alloc(ctx, 0, 0, 0);
1208 map = isl_map_lex_le(dim);
1209 assert(!isl_map_is_empty(map));
1213 void test_lexmin(struct isl_ctx *ctx)
1216 isl_map *map, *map2;
1220 str = "[p0, p1] -> { [] -> [] : "
1221 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1222 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1223 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1224 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1225 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1226 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1227 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1228 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1229 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1230 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1231 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1232 map = isl_map_read_from_str(ctx, str, -1);
1233 map = isl_map_lexmin(map);
1236 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1237 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1238 set = isl_set_read_from_str(ctx, str, -1);
1239 set = isl_set_lexmax(set);
1240 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1241 set2 = isl_set_read_from_str(ctx, str, -1);
1242 set = isl_set_intersect(set, set2);
1243 assert(!isl_set_is_empty(set));
1246 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1247 map = isl_map_read_from_str(ctx, str, -1);
1248 map = isl_map_lexmin(map);
1249 str = "{ [x] -> [5] : 6 <= x <= 8; "
1250 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1251 map2 = isl_map_read_from_str(ctx, str, -1);
1252 assert(isl_map_is_equal(map, map2));
1256 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1257 map = isl_map_read_from_str(ctx, str, -1);
1258 map2 = isl_map_copy(map);
1259 map = isl_map_lexmin(map);
1260 assert(isl_map_is_equal(map, map2));
1264 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1265 map = isl_map_read_from_str(ctx, str, -1);
1266 map = isl_map_lexmin(map);
1267 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1268 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1269 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1270 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1271 map2 = isl_map_read_from_str(ctx, str, -1);
1272 assert(isl_map_is_equal(map, map2));
1282 static int collect_must_may(__isl_take isl_map *dep, int must,
1283 void *dep_user, void *user)
1285 struct must_may *mm = (struct must_may *)user;
1288 mm->must = isl_map_union(mm->must, dep);
1290 mm->may = isl_map_union(mm->may, dep);
1295 static int common_space(void *first, void *second)
1297 int depth = *(int *)first;
1301 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1309 map2 = isl_map_read_from_str(map->ctx, str, -1);
1310 equal = isl_map_is_equal(map, map2);
1316 void test_dep(struct isl_ctx *ctx)
1321 isl_access_info *ai;
1328 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1329 map = isl_map_read_from_str(ctx, str, -1);
1330 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1332 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1333 map = isl_map_read_from_str(ctx, str, -1);
1334 ai = isl_access_info_add_source(ai, map, 1, &depth);
1336 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1337 map = isl_map_read_from_str(ctx, str, -1);
1338 ai = isl_access_info_add_source(ai, map, 1, &depth);
1340 flow = isl_access_info_compute_flow(ai);
1341 dim = isl_dim_alloc(ctx, 0, 3, 3);
1342 mm.must = isl_map_empty(isl_dim_copy(dim));
1343 mm.may = isl_map_empty(dim);
1345 isl_flow_foreach(flow, collect_must_may, &mm);
1347 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1348 " [1,10,0] -> [2,5,0] }";
1349 assert(map_is_equal(mm.must, str));
1350 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1351 assert(map_is_equal(mm.may, str));
1353 isl_map_free(mm.must);
1354 isl_map_free(mm.may);
1355 isl_flow_free(flow);
1358 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1359 map = isl_map_read_from_str(ctx, str, -1);
1360 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1362 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1363 map = isl_map_read_from_str(ctx, str, -1);
1364 ai = isl_access_info_add_source(ai, map, 1, &depth);
1366 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1367 map = isl_map_read_from_str(ctx, str, -1);
1368 ai = isl_access_info_add_source(ai, map, 0, &depth);
1370 flow = isl_access_info_compute_flow(ai);
1371 dim = isl_dim_alloc(ctx, 0, 3, 3);
1372 mm.must = isl_map_empty(isl_dim_copy(dim));
1373 mm.may = isl_map_empty(dim);
1375 isl_flow_foreach(flow, collect_must_may, &mm);
1377 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1378 assert(map_is_equal(mm.must, str));
1379 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1380 assert(map_is_equal(mm.may, str));
1382 isl_map_free(mm.must);
1383 isl_map_free(mm.may);
1384 isl_flow_free(flow);
1387 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1388 map = isl_map_read_from_str(ctx, str, -1);
1389 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1391 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1392 map = isl_map_read_from_str(ctx, str, -1);
1393 ai = isl_access_info_add_source(ai, map, 0, &depth);
1395 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1396 map = isl_map_read_from_str(ctx, str, -1);
1397 ai = isl_access_info_add_source(ai, map, 0, &depth);
1399 flow = isl_access_info_compute_flow(ai);
1400 dim = isl_dim_alloc(ctx, 0, 3, 3);
1401 mm.must = isl_map_empty(isl_dim_copy(dim));
1402 mm.may = isl_map_empty(dim);
1404 isl_flow_foreach(flow, collect_must_may, &mm);
1406 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1407 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1408 assert(map_is_equal(mm.may, str));
1409 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1410 assert(map_is_equal(mm.must, str));
1412 isl_map_free(mm.must);
1413 isl_map_free(mm.may);
1414 isl_flow_free(flow);
1417 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1418 map = isl_map_read_from_str(ctx, str, -1);
1419 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1421 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1422 map = isl_map_read_from_str(ctx, str, -1);
1423 ai = isl_access_info_add_source(ai, map, 0, &depth);
1425 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1426 map = isl_map_read_from_str(ctx, str, -1);
1427 ai = isl_access_info_add_source(ai, map, 0, &depth);
1429 flow = isl_access_info_compute_flow(ai);
1430 dim = isl_dim_alloc(ctx, 0, 3, 3);
1431 mm.must = isl_map_empty(isl_dim_copy(dim));
1432 mm.may = isl_map_empty(dim);
1434 isl_flow_foreach(flow, collect_must_may, &mm);
1436 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1437 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1438 assert(map_is_equal(mm.may, str));
1439 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1440 assert(map_is_equal(mm.must, str));
1442 isl_map_free(mm.must);
1443 isl_map_free(mm.may);
1444 isl_flow_free(flow);
1447 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1448 map = isl_map_read_from_str(ctx, str, -1);
1449 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1451 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1452 map = isl_map_read_from_str(ctx, str, -1);
1453 ai = isl_access_info_add_source(ai, map, 0, &depth);
1455 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1456 map = isl_map_read_from_str(ctx, str, -1);
1457 ai = isl_access_info_add_source(ai, map, 0, &depth);
1459 flow = isl_access_info_compute_flow(ai);
1460 dim = isl_dim_alloc(ctx, 0, 3, 3);
1461 mm.must = isl_map_empty(isl_dim_copy(dim));
1462 mm.may = isl_map_empty(dim);
1464 isl_flow_foreach(flow, collect_must_may, &mm);
1466 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1467 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1468 assert(map_is_equal(mm.may, str));
1469 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1470 assert(map_is_equal(mm.must, str));
1472 isl_map_free(mm.must);
1473 isl_map_free(mm.may);
1474 isl_flow_free(flow);
1479 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1480 map = isl_map_read_from_str(ctx, str, -1);
1481 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1483 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1484 map = isl_map_read_from_str(ctx, str, -1);
1485 ai = isl_access_info_add_source(ai, map, 1, &depth);
1487 flow = isl_access_info_compute_flow(ai);
1488 dim = isl_dim_alloc(ctx, 0, 5, 5);
1489 mm.must = isl_map_empty(isl_dim_copy(dim));
1490 mm.may = isl_map_empty(dim);
1492 isl_flow_foreach(flow, collect_must_may, &mm);
1494 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1495 assert(map_is_equal(mm.must, str));
1496 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1497 assert(map_is_equal(mm.may, str));
1499 isl_map_free(mm.must);
1500 isl_map_free(mm.may);
1501 isl_flow_free(flow);
1504 void test_sv(struct isl_ctx *ctx)
1509 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1510 map = isl_map_read_from_str(ctx, str, -1);
1511 assert(isl_map_is_single_valued(map));
1514 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1515 map = isl_map_read_from_str(ctx, str, -1);
1516 assert(!isl_map_is_single_valued(map));
1520 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1524 map = isl_map_read_from_str(ctx, str, -1);
1526 assert(isl_map_is_bijective(map));
1528 assert(!isl_map_is_bijective(map));
1532 void test_bijective(struct isl_ctx *ctx)
1534 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1535 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1536 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1537 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1538 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1539 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1540 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1541 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1542 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1543 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1544 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1545 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1546 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1549 void test_pwqp(struct isl_ctx *ctx)
1553 isl_pw_qpolynomial *pwqp1, *pwqp2;
1555 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1556 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1558 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1561 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1562 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1564 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1566 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1568 isl_pw_qpolynomial_free(pwqp1);
1570 str = "{ [i] -> i }";
1571 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1572 str = "{ [k] : exists a : k = 2a }";
1573 set = isl_set_read_from_str(ctx, str, 0);
1574 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1575 str = "{ [i] -> i }";
1576 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1578 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1580 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1582 isl_pw_qpolynomial_free(pwqp1);
1584 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1585 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1587 set = isl_set_read_from_str(ctx, str, 0);
1588 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1589 str = "{ [i] -> 16 }";
1590 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1592 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1594 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1596 isl_pw_qpolynomial_free(pwqp1);
1598 str = "{ [i] -> ([(i)/2]) }";
1599 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1600 str = "{ [k] : exists a : k = 2a+1 }";
1601 set = isl_set_read_from_str(ctx, str, 0);
1602 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1603 str = "{ [i] -> -1/2 + 1/2 * i }";
1604 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1606 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1608 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1610 isl_pw_qpolynomial_free(pwqp1);
1612 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1613 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1614 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1615 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1617 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1619 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1621 isl_pw_qpolynomial_free(pwqp1);
1623 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1624 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1625 str = "{ [x] -> x }";
1626 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1628 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1630 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1632 isl_pw_qpolynomial_free(pwqp1);
1635 void test_split_periods(isl_ctx *ctx)
1638 isl_pw_qpolynomial *pwqp;
1640 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1641 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1642 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1643 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1645 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1648 isl_pw_qpolynomial_free(pwqp);
1651 void test_union(isl_ctx *ctx)
1654 isl_union_set *uset1, *uset2;
1655 isl_union_map *umap1, *umap2;
1657 str = "{ [i] : 0 <= i <= 1 }";
1658 uset1 = isl_union_set_read_from_str(ctx, str);
1659 str = "{ [1] -> [0] }";
1660 umap1 = isl_union_map_read_from_str(ctx, str);
1662 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1663 assert(isl_union_map_is_equal(umap1, umap2));
1665 isl_union_map_free(umap1);
1666 isl_union_map_free(umap2);
1668 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1669 umap1 = isl_union_map_read_from_str(ctx, str);
1670 str = "{ A[i]; B[i] }";
1671 uset1 = isl_union_set_read_from_str(ctx, str);
1673 uset2 = isl_union_map_domain(umap1);
1675 assert(isl_union_set_is_equal(uset1, uset2));
1677 isl_union_set_free(uset1);
1678 isl_union_set_free(uset2);
1681 void test_bound(isl_ctx *ctx)
1684 isl_pw_qpolynomial *pwqp;
1685 isl_pw_qpolynomial_fold *pwf;
1687 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1688 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1689 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1690 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
1691 isl_pw_qpolynomial_fold_free(pwf);
1693 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1694 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1695 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1696 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 1);
1697 isl_pw_qpolynomial_fold_free(pwf);
1700 void test_lift(isl_ctx *ctx)
1703 isl_basic_map *bmap;
1704 isl_basic_set *bset;
1706 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1707 bset = isl_basic_set_read_from_str(ctx, str, 0);
1708 bset = isl_basic_set_lift(bset);
1709 bmap = isl_basic_map_from_range(bset);
1710 bset = isl_basic_map_domain(bmap);
1711 isl_basic_set_free(bset);
1714 void test_subset(isl_ctx *ctx)
1717 isl_set *set1, *set2;
1719 str = "{ [112, 0] }";
1720 set1 = isl_set_read_from_str(ctx, str, 0);
1721 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1722 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1723 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1724 set2 = isl_set_read_from_str(ctx, str, 0);
1725 assert(isl_set_is_subset(set1, set2));
1730 void test_factorize(isl_ctx *ctx)
1733 isl_basic_set *bset;
1736 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1737 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1738 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1739 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1740 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1741 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1742 "3i5 >= -2i0 - i2 + 3i4 }";
1743 bset = isl_basic_set_read_from_str(ctx, str, 0);
1744 f = isl_basic_set_factorizer(bset);
1746 isl_basic_set_free(bset);
1747 isl_factorizer_free(f);
1749 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1750 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1751 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1752 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1753 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1754 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1755 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1756 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1757 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1758 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1759 bset = isl_basic_set_read_from_str(ctx, str, 0);
1760 f = isl_basic_set_factorizer(bset);
1762 isl_basic_set_free(bset);
1763 isl_factorizer_free(f);
1768 struct isl_ctx *ctx;
1770 srcdir = getenv("srcdir");
1773 ctx = isl_ctx_alloc();
1774 test_factorize(ctx);
1779 test_split_periods(ctx);
1784 test_bijective(ctx);
1788 test_construction(ctx);
1791 test_application(ctx);
1792 test_affine_hull(ctx);
1793 test_convex_hull(ctx);