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 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
77 map = isl_map_read_from_str(ctx, str, -1);
78 str = "{ [new, old] -> [o0, o1] : "
79 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
80 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
81 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
82 map2 = isl_map_read_from_str(ctx, str, -1);
83 assert(isl_map_is_equal(map, map2));
87 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
88 map = isl_map_read_from_str(ctx, str, -1);
89 str = "{[new,old] -> [(new+1)%2,(old+1)%2]}";
90 map2 = isl_map_read_from_str(ctx, str, -1);
91 assert(isl_map_is_equal(map, map2));
95 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
98 void test_read(struct isl_ctx *ctx)
100 char filename[PATH_MAX];
103 struct isl_basic_set *bset1, *bset2;
104 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
106 n = snprintf(filename, sizeof(filename),
107 "%s/test_inputs/set.omega", srcdir);
108 assert(n < sizeof(filename));
109 input = fopen(filename, "r");
112 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
113 bset2 = isl_basic_set_read_from_str(ctx, str, 0);
115 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
117 isl_basic_set_free(bset1);
118 isl_basic_set_free(bset2);
123 void test_bounded(struct isl_ctx *ctx)
128 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }", -1);
129 bounded = isl_set_is_bounded(set);
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] : i <= n }", -1);
139 bounded = isl_set_is_bounded(set);
144 /* Construct the basic set { [i] : 5 <= i <= N } */
145 void test_construction(struct isl_ctx *ctx)
149 struct isl_basic_set *bset;
150 struct isl_constraint *c;
154 dim = isl_dim_set_alloc(ctx, 1, 1);
155 bset = isl_basic_set_universe(dim);
157 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
158 isl_int_set_si(v, -1);
159 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
160 isl_int_set_si(v, 1);
161 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
162 bset = isl_basic_set_add_constraint(bset, c);
164 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
165 isl_int_set_si(v, 1);
166 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
167 isl_int_set_si(v, -5);
168 isl_constraint_set_constant(c, v);
169 bset = isl_basic_set_add_constraint(bset, c);
171 isl_basic_set_free(bset);
176 void test_dim(struct isl_ctx *ctx)
179 isl_map *map1, *map2;
181 map1 = isl_map_read_from_str(ctx,
182 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
183 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
184 map2 = isl_map_read_from_str(ctx,
185 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
186 assert(isl_map_is_equal(map1, map2));
189 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
190 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }", -1);
191 assert(isl_map_is_equal(map1, map2));
196 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
197 map1 = isl_map_read_from_str(ctx, str, -1);
198 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
199 map2 = isl_map_read_from_str(ctx, str, -1);
200 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
201 assert(isl_map_is_equal(map1, map2));
207 void test_div(struct isl_ctx *ctx)
213 struct isl_basic_set *bset;
214 struct isl_constraint *c;
219 dim = isl_dim_set_alloc(ctx, 0, 1);
220 bset = isl_basic_set_universe(dim);
222 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
223 isl_int_set_si(v, -1);
224 isl_constraint_set_constant(c, v);
225 isl_int_set_si(v, 1);
226 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
227 div = isl_div_alloc(isl_basic_set_get_dim(bset));
228 c = isl_constraint_add_div(c, div, &pos);
229 isl_int_set_si(v, 3);
230 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
231 bset = isl_basic_set_add_constraint(bset, c);
233 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
234 isl_int_set_si(v, 1);
235 isl_constraint_set_constant(c, v);
236 isl_int_set_si(v, -1);
237 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
238 div = isl_div_alloc(isl_basic_set_get_dim(bset));
239 c = isl_constraint_add_div(c, div, &pos);
240 isl_int_set_si(v, 3);
241 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
242 bset = isl_basic_set_add_constraint(bset, c);
244 assert(bset && bset->n_div == 1);
245 isl_basic_set_free(bset);
248 dim = isl_dim_set_alloc(ctx, 0, 1);
249 bset = isl_basic_set_universe(dim);
251 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
252 isl_int_set_si(v, 1);
253 isl_constraint_set_constant(c, v);
254 isl_int_set_si(v, -1);
255 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
256 div = isl_div_alloc(isl_basic_set_get_dim(bset));
257 c = isl_constraint_add_div(c, div, &pos);
258 isl_int_set_si(v, 3);
259 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
260 bset = isl_basic_set_add_constraint(bset, c);
262 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
263 isl_int_set_si(v, -1);
264 isl_constraint_set_constant(c, v);
265 isl_int_set_si(v, 1);
266 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
267 div = isl_div_alloc(isl_basic_set_get_dim(bset));
268 c = isl_constraint_add_div(c, div, &pos);
269 isl_int_set_si(v, 3);
270 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
271 bset = isl_basic_set_add_constraint(bset, c);
273 assert(bset && bset->n_div == 1);
274 isl_basic_set_free(bset);
277 dim = isl_dim_set_alloc(ctx, 0, 1);
278 bset = isl_basic_set_universe(dim);
280 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
281 isl_int_set_si(v, 1);
282 isl_constraint_set_constant(c, v);
283 isl_int_set_si(v, -1);
284 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
285 div = isl_div_alloc(isl_basic_set_get_dim(bset));
286 c = isl_constraint_add_div(c, div, &pos);
287 isl_int_set_si(v, 3);
288 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
289 bset = isl_basic_set_add_constraint(bset, c);
291 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
292 isl_int_set_si(v, -3);
293 isl_constraint_set_constant(c, v);
294 isl_int_set_si(v, 1);
295 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
296 div = isl_div_alloc(isl_basic_set_get_dim(bset));
297 c = isl_constraint_add_div(c, div, &pos);
298 isl_int_set_si(v, 4);
299 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
300 bset = isl_basic_set_add_constraint(bset, c);
302 assert(bset && bset->n_div == 1);
303 isl_basic_set_free(bset);
306 dim = isl_dim_set_alloc(ctx, 0, 1);
307 bset = isl_basic_set_universe(dim);
309 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
310 isl_int_set_si(v, 2);
311 isl_constraint_set_constant(c, v);
312 isl_int_set_si(v, -1);
313 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
314 div = isl_div_alloc(isl_basic_set_get_dim(bset));
315 c = isl_constraint_add_div(c, div, &pos);
316 isl_int_set_si(v, 3);
317 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
318 bset = isl_basic_set_add_constraint(bset, c);
320 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
321 isl_int_set_si(v, -1);
322 isl_constraint_set_constant(c, v);
323 isl_int_set_si(v, 1);
324 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
325 div = isl_div_alloc(isl_basic_set_get_dim(bset));
326 c = isl_constraint_add_div(c, div, &pos);
327 isl_int_set_si(v, 6);
328 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
329 bset = isl_basic_set_add_constraint(bset, c);
331 assert(isl_basic_set_is_empty(bset));
332 isl_basic_set_free(bset);
335 dim = isl_dim_set_alloc(ctx, 0, 2);
336 bset = isl_basic_set_universe(dim);
338 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
339 isl_int_set_si(v, -1);
340 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
341 div = isl_div_alloc(isl_basic_set_get_dim(bset));
342 c = isl_constraint_add_div(c, div, &pos);
343 isl_int_set_si(v, 3);
344 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
345 bset = isl_basic_set_add_constraint(bset, c);
347 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
348 isl_int_set_si(v, 1);
349 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
350 isl_int_set_si(v, -3);
351 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
352 bset = isl_basic_set_add_constraint(bset, c);
354 assert(bset && bset->n_div == 0);
355 isl_basic_set_free(bset);
358 dim = isl_dim_set_alloc(ctx, 0, 2);
359 bset = isl_basic_set_universe(dim);
361 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
362 isl_int_set_si(v, -1);
363 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
364 div = isl_div_alloc(isl_basic_set_get_dim(bset));
365 c = isl_constraint_add_div(c, div, &pos);
366 isl_int_set_si(v, 6);
367 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
368 bset = isl_basic_set_add_constraint(bset, c);
370 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
371 isl_int_set_si(v, 1);
372 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
373 isl_int_set_si(v, -3);
374 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
375 bset = isl_basic_set_add_constraint(bset, c);
377 assert(bset && bset->n_div == 1);
378 isl_basic_set_free(bset);
381 /* This test is a bit tricky. We set up an equality
383 * Normalization of divs creates _two_ divs
386 * Afterwards e0 is removed again because it has coefficient -1
387 * and we end up with the original equality and div again.
388 * Perhaps we can avoid the introduction of this temporary div.
390 dim = isl_dim_set_alloc(ctx, 0, 3);
391 bset = isl_basic_set_universe(dim);
393 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
394 isl_int_set_si(v, -1);
395 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
396 isl_int_set_si(v, -3);
397 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
398 isl_int_set_si(v, -3);
399 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
400 div = isl_div_alloc(isl_basic_set_get_dim(bset));
401 c = isl_constraint_add_div(c, div, &pos);
402 isl_int_set_si(v, 6);
403 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
404 bset = isl_basic_set_add_constraint(bset, c);
406 /* Test disabled for now */
408 assert(bset && bset->n_div == 1);
410 isl_basic_set_free(bset);
413 dim = isl_dim_set_alloc(ctx, 0, 4);
414 bset = isl_basic_set_universe(dim);
416 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
417 isl_int_set_si(v, -1);
418 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
419 isl_int_set_si(v, -3);
420 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
421 isl_int_set_si(v, -3);
422 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
423 div = isl_div_alloc(isl_basic_set_get_dim(bset));
424 c = isl_constraint_add_div(c, div, &pos);
425 isl_int_set_si(v, 6);
426 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
427 bset = isl_basic_set_add_constraint(bset, c);
429 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
430 isl_int_set_si(v, -1);
431 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
432 isl_int_set_si(v, 1);
433 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
434 isl_int_set_si(v, 1);
435 isl_constraint_set_constant(c, v);
436 bset = isl_basic_set_add_constraint(bset, c);
438 /* Test disabled for now */
440 assert(bset && bset->n_div == 1);
442 isl_basic_set_free(bset);
445 dim = isl_dim_set_alloc(ctx, 0, 2);
446 bset = isl_basic_set_universe(dim);
448 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
449 isl_int_set_si(v, 1);
450 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
451 isl_int_set_si(v, -1);
452 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
453 div = isl_div_alloc(isl_basic_set_get_dim(bset));
454 c = isl_constraint_add_div(c, div, &pos);
455 isl_int_set_si(v, -2);
456 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
457 bset = isl_basic_set_add_constraint(bset, c);
459 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
460 isl_int_set_si(v, -1);
461 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
462 div = isl_div_alloc(isl_basic_set_get_dim(bset));
463 c = isl_constraint_add_div(c, div, &pos);
464 isl_int_set_si(v, 3);
465 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
466 isl_int_set_si(v, 2);
467 isl_constraint_set_constant(c, v);
468 bset = isl_basic_set_add_constraint(bset, c);
470 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
472 assert(!isl_basic_set_is_empty(bset));
474 isl_basic_set_free(bset);
477 dim = isl_dim_set_alloc(ctx, 0, 2);
478 bset = isl_basic_set_universe(dim);
480 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
481 isl_int_set_si(v, 1);
482 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
483 div = isl_div_alloc(isl_basic_set_get_dim(bset));
484 c = isl_constraint_add_div(c, div, &pos);
485 isl_int_set_si(v, -2);
486 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
487 bset = isl_basic_set_add_constraint(bset, c);
489 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
491 isl_basic_set_free(bset);
496 void test_application_case(struct isl_ctx *ctx, const char *name)
498 char filename[PATH_MAX];
501 struct isl_basic_set *bset1, *bset2;
502 struct isl_basic_map *bmap;
504 n = snprintf(filename, sizeof(filename),
505 "%s/test_inputs/%s.omega", srcdir, name);
506 assert(n < sizeof(filename));
507 input = fopen(filename, "r");
510 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
511 bmap = isl_basic_map_read_from_file(ctx, input, 0);
513 bset1 = isl_basic_set_apply(bset1, bmap);
515 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
517 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
519 isl_basic_set_free(bset1);
520 isl_basic_set_free(bset2);
525 void test_application(struct isl_ctx *ctx)
527 test_application_case(ctx, "application");
528 test_application_case(ctx, "application2");
531 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
533 char filename[PATH_MAX];
536 struct isl_basic_set *bset1, *bset2;
538 n = snprintf(filename, sizeof(filename),
539 "%s/test_inputs/%s.polylib", srcdir, name);
540 assert(n < sizeof(filename));
541 input = fopen(filename, "r");
544 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
545 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
547 bset1 = isl_basic_set_affine_hull(bset1);
549 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
551 isl_basic_set_free(bset1);
552 isl_basic_set_free(bset2);
557 void test_affine_hull(struct isl_ctx *ctx)
559 test_affine_hull_case(ctx, "affine2");
560 test_affine_hull_case(ctx, "affine");
561 test_affine_hull_case(ctx, "affine3");
564 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
566 char filename[PATH_MAX];
569 struct isl_basic_set *bset1, *bset2;
572 n = snprintf(filename, sizeof(filename),
573 "%s/test_inputs/%s.polylib", srcdir, name);
574 assert(n < sizeof(filename));
575 input = fopen(filename, "r");
578 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
579 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
581 set = isl_basic_set_union(bset1, bset2);
582 bset1 = isl_set_convex_hull(set);
584 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
586 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
588 isl_basic_set_free(bset1);
589 isl_basic_set_free(bset2);
594 void test_convex_hull_algo(struct isl_ctx *ctx, int convex)
596 const char *str1, *str2;
597 isl_set *set1, *set2;
598 int orig_convex = ctx->opt->convex;
599 ctx->opt->convex = convex;
601 test_convex_hull_case(ctx, "convex0");
602 test_convex_hull_case(ctx, "convex1");
603 test_convex_hull_case(ctx, "convex2");
604 test_convex_hull_case(ctx, "convex3");
605 test_convex_hull_case(ctx, "convex4");
606 test_convex_hull_case(ctx, "convex5");
607 test_convex_hull_case(ctx, "convex6");
608 test_convex_hull_case(ctx, "convex7");
609 test_convex_hull_case(ctx, "convex8");
610 test_convex_hull_case(ctx, "convex9");
611 test_convex_hull_case(ctx, "convex10");
612 test_convex_hull_case(ctx, "convex11");
613 test_convex_hull_case(ctx, "convex12");
614 test_convex_hull_case(ctx, "convex13");
615 test_convex_hull_case(ctx, "convex14");
616 test_convex_hull_case(ctx, "convex15");
618 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
619 "(i0 = 1 and i1 = 0 and i2 = 1) or "
620 "(i0 = 0 and i1 = 0 and i2 = 0) }";
621 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
622 set1 = isl_set_read_from_str(ctx, str1, -1);
623 set2 = isl_set_read_from_str(ctx, str2, -1);
624 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
625 assert(isl_set_is_equal(set1, set2));
629 ctx->opt->convex = orig_convex;
632 void test_convex_hull(struct isl_ctx *ctx)
634 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_FM);
635 test_convex_hull_algo(ctx, ISL_CONVEX_HULL_WRAP);
638 void test_gist_case(struct isl_ctx *ctx, const char *name)
640 char filename[PATH_MAX];
643 struct isl_basic_set *bset1, *bset2;
645 n = snprintf(filename, sizeof(filename),
646 "%s/test_inputs/%s.polylib", srcdir, name);
647 assert(n < sizeof(filename));
648 input = fopen(filename, "r");
651 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
652 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
654 bset1 = isl_basic_set_gist(bset1, bset2);
656 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
658 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
660 isl_basic_set_free(bset1);
661 isl_basic_set_free(bset2);
666 void test_gist(struct isl_ctx *ctx)
669 isl_basic_set *bset1, *bset2;
671 test_gist_case(ctx, "gist1");
673 str = "[p0, p2, p3, p5, p6, p10] -> { [] : "
674 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
675 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
676 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
677 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
678 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
679 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
680 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
681 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
682 bset1 = isl_basic_set_read_from_str(ctx, str, -1);
683 str = "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
684 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
685 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
686 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
687 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
688 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
689 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
690 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
691 bset2 = isl_basic_set_read_from_str(ctx, str, -1);
692 bset1 = isl_basic_set_gist(bset1, bset2);
693 assert(bset1 && bset1->n_div == 0);
694 isl_basic_set_free(bset1);
697 void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
701 set = isl_set_read_from_str(ctx, str, -1);
702 set = isl_set_coalesce(set);
703 set2 = isl_set_read_from_str(ctx, str, -1);
704 assert(isl_set_is_equal(set, set2));
706 assert(set && set->n == 1);
711 void test_coalesce(struct isl_ctx *ctx)
714 struct isl_set *set, *set2;
715 struct isl_map *map, *map2;
717 set = isl_set_read_from_str(ctx,
718 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
719 "y >= x & x >= 2 & 5 >= y }", -1);
720 set = isl_set_coalesce(set);
721 assert(set && set->n == 1);
724 set = isl_set_read_from_str(ctx,
725 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
726 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
727 set = isl_set_coalesce(set);
728 assert(set && set->n == 1);
731 set = isl_set_read_from_str(ctx,
732 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
733 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
734 set = isl_set_coalesce(set);
735 assert(set && set->n == 2);
738 set = isl_set_read_from_str(ctx,
739 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
740 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
741 set = isl_set_coalesce(set);
742 assert(set && set->n == 1);
745 set = isl_set_read_from_str(ctx,
746 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
747 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
748 set = isl_set_coalesce(set);
749 assert(set && set->n == 2);
752 set = isl_set_read_from_str(ctx,
753 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
754 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
755 set = isl_set_coalesce(set);
756 assert(set && set->n == 2);
759 set = isl_set_read_from_str(ctx,
760 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
761 "y >= 0 & x = 6 & y <= 6}", -1);
762 set = isl_set_coalesce(set);
763 assert(set && set->n == 1);
766 set = isl_set_read_from_str(ctx,
767 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
768 "y >= 0 & x = 7 & y <= 6}", -1);
769 set = isl_set_coalesce(set);
770 assert(set && set->n == 2);
773 set = isl_set_read_from_str(ctx,
774 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
775 "y >= 0 & x = 6 & y <= 5}", -1);
776 set = isl_set_coalesce(set);
777 assert(set && set->n == 1);
778 set2 = 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 assert(isl_set_is_equal(set, set2));
785 set = isl_set_read_from_str(ctx,
786 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
787 "y >= 0 & x = 6 & y <= 7}", -1);
788 set = isl_set_coalesce(set);
789 assert(set && set->n == 2);
792 set = isl_set_read_from_str(ctx,
793 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
794 set = isl_set_coalesce(set);
795 assert(set && set->n == 1);
796 set2 = isl_set_read_from_str(ctx,
797 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
798 assert(isl_set_is_equal(set, set2));
802 set = isl_set_read_from_str(ctx,
803 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
804 set = isl_set_coalesce(set);
805 set2 = isl_set_read_from_str(ctx,
806 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
807 assert(isl_set_is_equal(set, set2));
811 set = isl_set_read_from_str(ctx,
812 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
813 "2 <= i and i <= n }", -1);
814 set = isl_set_coalesce(set);
815 assert(set && set->n == 1);
816 set2 = isl_set_read_from_str(ctx,
817 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
818 "2 <= i and i <= n }", -1);
819 assert(isl_set_is_equal(set, set2));
823 map = isl_map_read_from_str(ctx,
824 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
825 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
826 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
827 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
828 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
829 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
830 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
831 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
832 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
833 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
834 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
835 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
836 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
837 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
838 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
839 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
840 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
841 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
842 map = isl_map_coalesce(map);
843 map2 = isl_map_read_from_str(ctx,
844 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
845 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
846 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
847 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
848 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
849 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
850 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
851 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
852 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
853 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
854 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
855 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
856 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
857 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
858 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
859 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
860 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
861 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
862 assert(isl_map_is_equal(map, map2));
866 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
867 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
868 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
869 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
870 map = isl_map_read_from_str(ctx, str, -1);
871 map = isl_map_coalesce(map);
872 map2 = isl_map_read_from_str(ctx, str, -1);
873 assert(isl_map_is_equal(map, map2));
877 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
878 "[o0, o1, o2, o3, o4, o5, o6] : "
879 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
880 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
881 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
882 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
883 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
884 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
885 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
886 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
887 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
888 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
889 "o6 >= i3 + i6 - o3 and M >= 0 and "
890 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
891 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
892 map = isl_map_read_from_str(ctx, str, -1);
893 map = isl_map_coalesce(map);
894 map2 = isl_map_read_from_str(ctx, str, -1);
895 assert(isl_map_is_equal(map, map2));
899 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
900 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
901 "(o0 = 0 and M >= 2 and N >= 3) or "
902 "(M = 0 and o0 = 0 and N >= 3) }";
903 map = isl_map_read_from_str(ctx, str, -1);
904 map = isl_map_coalesce(map);
905 map2 = isl_map_read_from_str(ctx, str, -1);
906 assert(isl_map_is_equal(map, map2));
910 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
911 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
912 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
913 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
914 map = isl_map_read_from_str(ctx, str, -1);
915 map = isl_map_coalesce(map);
916 map2 = isl_map_read_from_str(ctx, str, -1);
917 assert(isl_map_is_equal(map, map2));
921 test_coalesce_set(ctx,
922 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
923 "(i1 = M and M >= 1) }", 0);
924 test_coalesce_set(ctx,
925 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
926 test_coalesce_set(ctx,
927 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
928 "(y = 3 and x = 1) }", 1);
929 test_coalesce_set(ctx,
930 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
931 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
932 "i1 <= M and i3 <= M and i4 <= M) or "
933 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
934 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
935 "i4 <= -1 + M) }", 1);
936 test_coalesce_set(ctx,
937 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
938 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
939 test_coalesce_set(ctx,
940 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
941 "-x - y + 1 >= 0 and -3 <= z <= 3;"
942 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
943 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
944 test_coalesce_set(ctx,
945 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
946 test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
947 test_coalesce_set(ctx,
948 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
949 test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
950 test_coalesce_set(ctx, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
951 test_coalesce_set(ctx, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
952 test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
953 test_coalesce_set(ctx, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
954 test_coalesce_set(ctx, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
955 test_coalesce_set(ctx, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
958 void test_closure(struct isl_ctx *ctx)
966 /* COCOA example 1 */
967 map = isl_map_read_from_str(ctx,
968 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
969 "1 <= i and i < n and 1 <= j and j < n or "
970 "i2 = i + 1 and j2 = j - 1 and "
971 "1 <= i and i < n and 2 <= j and j <= n }", -1);
972 map = isl_map_power(map, &exact);
976 /* COCOA example 1 */
977 map = isl_map_read_from_str(ctx,
978 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
979 "1 <= i and i < n and 1 <= j and j < n or "
980 "i2 = i + 1 and j2 = j - 1 and "
981 "1 <= i and i < n and 2 <= j and j <= n }", -1);
982 map = isl_map_transitive_closure(map, &exact);
984 map2 = isl_map_read_from_str(ctx,
985 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
986 "1 <= i and i < n and 1 <= j and j <= n and "
987 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
988 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
989 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
990 assert(isl_map_is_equal(map, map2));
994 map = isl_map_read_from_str(ctx,
995 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
996 " 0 <= y and y <= n }", -1);
997 map = isl_map_transitive_closure(map, &exact);
998 map2 = isl_map_read_from_str(ctx,
999 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1000 " 0 <= y and y <= n }", -1);
1001 assert(isl_map_is_equal(map, map2));
1005 /* COCOA example 2 */
1006 map = isl_map_read_from_str(ctx,
1007 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1008 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1009 "i2 = i + 2 and j2 = j - 2 and "
1010 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
1011 map = isl_map_transitive_closure(map, &exact);
1013 map2 = isl_map_read_from_str(ctx,
1014 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1015 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1016 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1017 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1018 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
1019 assert(isl_map_is_equal(map, map2));
1023 /* COCOA Fig.2 left */
1024 map = isl_map_read_from_str(ctx,
1025 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1026 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1028 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1029 "j <= 2 i - 3 and j <= n - 2 or "
1030 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1031 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1032 map = isl_map_transitive_closure(map, &exact);
1036 /* COCOA Fig.2 right */
1037 map = isl_map_read_from_str(ctx,
1038 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1039 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1041 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1042 "j <= 2 i - 4 and j <= n - 3 or "
1043 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1044 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1045 map = isl_map_power(map, &exact);
1049 /* COCOA Fig.2 right */
1050 map = isl_map_read_from_str(ctx,
1051 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1052 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1054 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1055 "j <= 2 i - 4 and j <= n - 3 or "
1056 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1057 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1058 map = isl_map_transitive_closure(map, &exact);
1060 map2 = isl_map_read_from_str(ctx,
1061 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1062 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1063 "j <= n and 3 + i + 2 j <= 3 n and "
1064 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1065 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1066 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1067 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1068 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1069 assert(isl_map_is_equal(map, map2));
1073 /* COCOA Fig.1 right */
1074 dom = isl_set_read_from_str(ctx,
1075 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1076 "2 x - 3 y + 3 >= 0 }", -1);
1077 right = isl_map_read_from_str(ctx,
1078 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1079 up = isl_map_read_from_str(ctx,
1080 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1081 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1082 right = isl_map_intersect_range(right, isl_set_copy(dom));
1083 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1084 up = isl_map_intersect_range(up, dom);
1085 map = isl_map_union(up, right);
1086 map = isl_map_transitive_closure(map, &exact);
1088 map2 = isl_map_read_from_str(ctx,
1089 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1090 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1091 assert(isl_map_is_equal(map, map2));
1095 /* COCOA Theorem 1 counter example */
1096 map = isl_map_read_from_str(ctx,
1097 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1098 "i2 = 1 and j2 = j or "
1099 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1100 map = isl_map_transitive_closure(map, &exact);
1104 map = isl_map_read_from_str(ctx,
1105 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1106 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1107 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1108 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1109 map = isl_map_transitive_closure(map, &exact);
1113 /* Kelly et al 1996, fig 12 */
1114 map = isl_map_read_from_str(ctx,
1115 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1116 "1 <= i,j,j+1 <= n or "
1117 "j = n and j2 = 1 and i2 = i + 1 and "
1118 "1 <= i,i+1 <= n }", -1);
1119 map = isl_map_transitive_closure(map, &exact);
1121 map2 = isl_map_read_from_str(ctx,
1122 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1123 "1 <= i <= n and i = i2 or "
1124 "1 <= i < i2 <= n and 1 <= j <= n and "
1125 "1 <= j2 <= n }", -1);
1126 assert(isl_map_is_equal(map, map2));
1130 /* Omega's closure4 */
1131 map = isl_map_read_from_str(ctx,
1132 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1133 "1 <= x,y <= 10 or "
1134 "x2 = x + 1 and y2 = y and "
1135 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1136 map = isl_map_transitive_closure(map, &exact);
1140 map = isl_map_read_from_str(ctx,
1141 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1142 map = isl_map_transitive_closure(map, &exact);
1144 map2 = isl_map_read_from_str(ctx,
1145 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1146 assert(isl_map_is_equal(map, map2));
1150 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1151 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1152 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1153 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1154 map = isl_map_read_from_str(ctx, str, -1);
1155 map = isl_map_transitive_closure(map, &exact);
1157 map2 = isl_map_read_from_str(ctx, str, -1);
1158 assert(isl_map_is_equal(map, map2));
1162 str = "{[0] -> [1]; [2] -> [3]}";
1163 map = isl_map_read_from_str(ctx, str, -1);
1164 map = isl_map_transitive_closure(map, &exact);
1166 map2 = isl_map_read_from_str(ctx, str, -1);
1167 assert(isl_map_is_equal(map, map2));
1171 str = "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1172 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1173 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1174 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1175 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1176 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1177 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1178 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 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, 1, 0, i0] -> [i5, 2]] -> "
1182 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1183 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 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, 2, 0, i0] -> [i5, 2]] -> "
1187 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1188 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 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 map = isl_map_read_from_str(ctx, str, -1);
1192 map = isl_map_transitive_closure(map, NULL);
1197 void test_lex(struct isl_ctx *ctx)
1202 dim = isl_dim_alloc(ctx, 0, 0, 0);
1203 map = isl_map_lex_le(dim);
1204 assert(!isl_map_is_empty(map));
1208 void test_lexmin(struct isl_ctx *ctx)
1211 isl_map *map, *map2;
1215 str = "[p0, p1] -> { [] -> [] : "
1216 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1217 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1218 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1219 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1220 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1221 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1222 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1223 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1224 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1225 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1226 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1227 map = isl_map_read_from_str(ctx, str, -1);
1228 map = isl_map_lexmin(map);
1231 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1232 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1233 set = isl_set_read_from_str(ctx, str, -1);
1234 set = isl_set_lexmax(set);
1235 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1236 set2 = isl_set_read_from_str(ctx, str, -1);
1237 set = isl_set_intersect(set, set2);
1238 assert(!isl_set_is_empty(set));
1241 str = "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1242 map = isl_map_read_from_str(ctx, str, -1);
1243 map = isl_map_lexmin(map);
1244 str = "{ [x] -> [5] : 6 <= x <= 8; "
1245 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1246 map2 = isl_map_read_from_str(ctx, str, -1);
1247 assert(isl_map_is_equal(map, map2));
1251 str = "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1252 map = isl_map_read_from_str(ctx, str, -1);
1253 map2 = isl_map_copy(map);
1254 map = isl_map_lexmin(map);
1255 assert(isl_map_is_equal(map, map2));
1259 str = "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1260 map = isl_map_read_from_str(ctx, str, -1);
1261 map = isl_map_lexmin(map);
1262 str = "{ [x] -> [y] : (4y = x and x >= 0) or "
1263 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1264 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1265 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1266 map2 = isl_map_read_from_str(ctx, str, -1);
1267 assert(isl_map_is_equal(map, map2));
1277 static int collect_must_may(__isl_take isl_map *dep, int must,
1278 void *dep_user, void *user)
1280 struct must_may *mm = (struct must_may *)user;
1283 mm->must = isl_map_union(mm->must, dep);
1285 mm->may = isl_map_union(mm->may, dep);
1290 static int common_space(void *first, void *second)
1292 int depth = *(int *)first;
1296 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1304 map2 = isl_map_read_from_str(map->ctx, str, -1);
1305 equal = isl_map_is_equal(map, map2);
1311 void test_dep(struct isl_ctx *ctx)
1316 isl_access_info *ai;
1323 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1324 map = isl_map_read_from_str(ctx, str, -1);
1325 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1327 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1328 map = isl_map_read_from_str(ctx, str, -1);
1329 ai = isl_access_info_add_source(ai, map, 1, &depth);
1331 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1332 map = isl_map_read_from_str(ctx, str, -1);
1333 ai = isl_access_info_add_source(ai, map, 1, &depth);
1335 flow = isl_access_info_compute_flow(ai);
1336 dim = isl_dim_alloc(ctx, 0, 3, 3);
1337 mm.must = isl_map_empty(isl_dim_copy(dim));
1338 mm.may = isl_map_empty(dim);
1340 isl_flow_foreach(flow, collect_must_may, &mm);
1342 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1343 " [1,10,0] -> [2,5,0] }";
1344 assert(map_is_equal(mm.must, str));
1345 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1346 assert(map_is_equal(mm.may, str));
1348 isl_map_free(mm.must);
1349 isl_map_free(mm.may);
1350 isl_flow_free(flow);
1353 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1354 map = isl_map_read_from_str(ctx, str, -1);
1355 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1357 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1358 map = isl_map_read_from_str(ctx, str, -1);
1359 ai = isl_access_info_add_source(ai, map, 1, &depth);
1361 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1362 map = isl_map_read_from_str(ctx, str, -1);
1363 ai = isl_access_info_add_source(ai, map, 0, &depth);
1365 flow = isl_access_info_compute_flow(ai);
1366 dim = isl_dim_alloc(ctx, 0, 3, 3);
1367 mm.must = isl_map_empty(isl_dim_copy(dim));
1368 mm.may = isl_map_empty(dim);
1370 isl_flow_foreach(flow, collect_must_may, &mm);
1372 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1373 assert(map_is_equal(mm.must, str));
1374 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1375 assert(map_is_equal(mm.may, str));
1377 isl_map_free(mm.must);
1378 isl_map_free(mm.may);
1379 isl_flow_free(flow);
1382 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1383 map = isl_map_read_from_str(ctx, str, -1);
1384 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1386 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1387 map = isl_map_read_from_str(ctx, str, -1);
1388 ai = isl_access_info_add_source(ai, map, 0, &depth);
1390 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1391 map = isl_map_read_from_str(ctx, str, -1);
1392 ai = isl_access_info_add_source(ai, map, 0, &depth);
1394 flow = isl_access_info_compute_flow(ai);
1395 dim = isl_dim_alloc(ctx, 0, 3, 3);
1396 mm.must = isl_map_empty(isl_dim_copy(dim));
1397 mm.may = isl_map_empty(dim);
1399 isl_flow_foreach(flow, collect_must_may, &mm);
1401 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1402 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1403 assert(map_is_equal(mm.may, str));
1404 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1405 assert(map_is_equal(mm.must, str));
1407 isl_map_free(mm.must);
1408 isl_map_free(mm.may);
1409 isl_flow_free(flow);
1412 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1413 map = isl_map_read_from_str(ctx, str, -1);
1414 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1416 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1417 map = isl_map_read_from_str(ctx, str, -1);
1418 ai = isl_access_info_add_source(ai, map, 0, &depth);
1420 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1421 map = isl_map_read_from_str(ctx, str, -1);
1422 ai = isl_access_info_add_source(ai, map, 0, &depth);
1424 flow = isl_access_info_compute_flow(ai);
1425 dim = isl_dim_alloc(ctx, 0, 3, 3);
1426 mm.must = isl_map_empty(isl_dim_copy(dim));
1427 mm.may = isl_map_empty(dim);
1429 isl_flow_foreach(flow, collect_must_may, &mm);
1431 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1432 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1433 assert(map_is_equal(mm.may, str));
1434 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1435 assert(map_is_equal(mm.must, str));
1437 isl_map_free(mm.must);
1438 isl_map_free(mm.may);
1439 isl_flow_free(flow);
1442 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1443 map = isl_map_read_from_str(ctx, str, -1);
1444 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1446 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1447 map = isl_map_read_from_str(ctx, str, -1);
1448 ai = isl_access_info_add_source(ai, map, 0, &depth);
1450 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1451 map = isl_map_read_from_str(ctx, str, -1);
1452 ai = isl_access_info_add_source(ai, map, 0, &depth);
1454 flow = isl_access_info_compute_flow(ai);
1455 dim = isl_dim_alloc(ctx, 0, 3, 3);
1456 mm.must = isl_map_empty(isl_dim_copy(dim));
1457 mm.may = isl_map_empty(dim);
1459 isl_flow_foreach(flow, collect_must_may, &mm);
1461 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1462 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1463 assert(map_is_equal(mm.may, str));
1464 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1465 assert(map_is_equal(mm.must, str));
1467 isl_map_free(mm.must);
1468 isl_map_free(mm.may);
1469 isl_flow_free(flow);
1474 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1475 map = isl_map_read_from_str(ctx, str, -1);
1476 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1478 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1479 map = isl_map_read_from_str(ctx, str, -1);
1480 ai = isl_access_info_add_source(ai, map, 1, &depth);
1482 flow = isl_access_info_compute_flow(ai);
1483 dim = isl_dim_alloc(ctx, 0, 5, 5);
1484 mm.must = isl_map_empty(isl_dim_copy(dim));
1485 mm.may = isl_map_empty(dim);
1487 isl_flow_foreach(flow, collect_must_may, &mm);
1489 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1490 assert(map_is_equal(mm.must, str));
1491 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1492 assert(map_is_equal(mm.may, str));
1494 isl_map_free(mm.must);
1495 isl_map_free(mm.may);
1496 isl_flow_free(flow);
1499 void test_sv(struct isl_ctx *ctx)
1504 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1505 map = isl_map_read_from_str(ctx, str, -1);
1506 assert(isl_map_is_single_valued(map));
1509 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1510 map = isl_map_read_from_str(ctx, str, -1);
1511 assert(!isl_map_is_single_valued(map));
1515 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1519 map = isl_map_read_from_str(ctx, str, -1);
1521 assert(isl_map_is_bijective(map));
1523 assert(!isl_map_is_bijective(map));
1527 void test_bijective(struct isl_ctx *ctx)
1529 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1530 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1531 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1532 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1533 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1534 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1535 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1536 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1537 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1538 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1539 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1540 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1541 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1544 void test_pwqp(struct isl_ctx *ctx)
1548 isl_pw_qpolynomial *pwqp1, *pwqp2;
1550 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1551 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1553 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1556 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1557 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1559 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1561 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1563 isl_pw_qpolynomial_free(pwqp1);
1565 str = "{ [i] -> i }";
1566 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1567 str = "{ [k] : exists a : k = 2a }";
1568 set = isl_set_read_from_str(ctx, str, 0);
1569 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1570 str = "{ [i] -> i }";
1571 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1573 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1575 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1577 isl_pw_qpolynomial_free(pwqp1);
1579 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1580 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1582 set = isl_set_read_from_str(ctx, str, 0);
1583 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1584 str = "{ [i] -> 16 }";
1585 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1587 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1589 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1591 isl_pw_qpolynomial_free(pwqp1);
1593 str = "{ [i] -> ([(i)/2]) }";
1594 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1595 str = "{ [k] : exists a : k = 2a+1 }";
1596 set = isl_set_read_from_str(ctx, str, 0);
1597 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1598 str = "{ [i] -> -1/2 + 1/2 * i }";
1599 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1601 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1603 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1605 isl_pw_qpolynomial_free(pwqp1);
1607 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1608 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1609 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1610 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1612 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1614 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1616 isl_pw_qpolynomial_free(pwqp1);
1618 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1619 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1620 str = "{ [x] -> x }";
1621 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1623 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1625 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1627 isl_pw_qpolynomial_free(pwqp1);
1630 void test_split_periods(isl_ctx *ctx)
1633 isl_pw_qpolynomial *pwqp;
1635 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1636 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1637 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1638 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1640 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1643 isl_pw_qpolynomial_free(pwqp);
1646 void test_union(isl_ctx *ctx)
1649 isl_union_set *uset1, *uset2;
1650 isl_union_map *umap1, *umap2;
1652 str = "{ [i] : 0 <= i <= 1 }";
1653 uset1 = isl_union_set_read_from_str(ctx, str);
1654 str = "{ [1] -> [0] }";
1655 umap1 = isl_union_map_read_from_str(ctx, str);
1657 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1658 assert(isl_union_map_is_equal(umap1, umap2));
1660 isl_union_map_free(umap1);
1661 isl_union_map_free(umap2);
1663 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1664 umap1 = isl_union_map_read_from_str(ctx, str);
1665 str = "{ A[i]; B[i] }";
1666 uset1 = isl_union_set_read_from_str(ctx, str);
1668 uset2 = isl_union_map_domain(umap1);
1670 assert(isl_union_set_is_equal(uset1, uset2));
1672 isl_union_set_free(uset1);
1673 isl_union_set_free(uset2);
1676 void test_bound(isl_ctx *ctx)
1679 isl_pw_qpolynomial *pwqp;
1680 isl_pw_qpolynomial_fold *pwf;
1682 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1683 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1684 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1685 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
1686 isl_pw_qpolynomial_fold_free(pwf);
1688 str = "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1689 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1690 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1691 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 1);
1692 isl_pw_qpolynomial_fold_free(pwf);
1695 void test_lift(isl_ctx *ctx)
1698 isl_basic_map *bmap;
1699 isl_basic_set *bset;
1701 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1702 bset = isl_basic_set_read_from_str(ctx, str, 0);
1703 bset = isl_basic_set_lift(bset);
1704 bmap = isl_basic_map_from_range(bset);
1705 bset = isl_basic_map_domain(bmap);
1706 isl_basic_set_free(bset);
1709 void test_subset(isl_ctx *ctx)
1712 isl_set *set1, *set2;
1714 str = "{ [112, 0] }";
1715 set1 = isl_set_read_from_str(ctx, str, 0);
1716 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1717 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1718 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1719 set2 = isl_set_read_from_str(ctx, str, 0);
1720 assert(isl_set_is_subset(set1, set2));
1725 void test_factorize(isl_ctx *ctx)
1728 isl_basic_set *bset;
1731 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1732 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1733 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1734 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1735 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1736 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1737 "3i5 >= -2i0 - i2 + 3i4 }";
1738 bset = isl_basic_set_read_from_str(ctx, str, 0);
1739 f = isl_basic_set_factorizer(bset);
1741 isl_basic_set_free(bset);
1742 isl_factorizer_free(f);
1744 str = "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1745 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1746 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1747 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1748 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1749 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1750 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1751 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1752 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1753 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1754 bset = isl_basic_set_read_from_str(ctx, str, 0);
1755 f = isl_basic_set_factorizer(bset);
1757 isl_basic_set_free(bset);
1758 isl_factorizer_free(f);
1763 struct isl_ctx *ctx;
1765 srcdir = getenv("srcdir");
1768 ctx = isl_ctx_alloc();
1769 test_factorize(ctx);
1774 test_split_periods(ctx);
1779 test_bijective(ctx);
1783 test_construction(ctx);
1786 test_application(ctx);
1787 test_affine_hull(ctx);
1788 test_convex_hull(ctx);