isl 0.05.1
[isl.git] / isl_test.c
blobaf517f1778299044f6755cccb02aeaf081d6790d
1 /*
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
8 */
10 #include <assert.h>
11 #include <stdio.h>
12 #include <limits.h>
13 #include <isl/ctx.h>
14 #include <isl/set.h>
15 #include <isl/flow.h>
16 #include <isl/constraint.h>
17 #include <isl/polynomial.h>
18 #include <isl/union_map.h>
19 #include <isl_map_private.h>
21 static char *srcdir;
23 void test_parse_map(isl_ctx *ctx, const char *str)
25 isl_map *map;
27 map = isl_map_read_from_str(ctx, str, -1);
28 assert(map);
29 isl_map_free(map);
32 void test_parse_pwqp(isl_ctx *ctx, const char *str)
34 isl_pw_qpolynomial *pwqp;
36 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
37 assert(pwqp);
38 isl_pw_qpolynomial_free(pwqp);
41 void test_parse(struct isl_ctx *ctx)
43 isl_map *map, *map2;
44 const char *str;
46 str = "{ [i] -> [-i] }";
47 map = isl_map_read_from_str(ctx, str, -1);
48 assert(map);
49 isl_map_free(map);
51 str = "{ A[i] -> L[([i/3])] }";
52 map = isl_map_read_from_str(ctx, str, -1);
53 assert(map);
54 isl_map_free(map);
56 test_parse_map(ctx, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
58 str = "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
59 map = isl_map_read_from_str(ctx, str, -1);
60 str = "{ [new, old] -> [o0, o1] : "
61 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
62 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
63 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
64 map2 = isl_map_read_from_str(ctx, str, -1);
65 assert(isl_map_is_equal(map, map2));
66 isl_map_free(map);
67 isl_map_free(map2);
69 test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }");
72 void test_read(struct isl_ctx *ctx)
74 char filename[PATH_MAX];
75 FILE *input;
76 int n;
77 struct isl_basic_set *bset1, *bset2;
78 const char *str = "{[y]: Exists ( alpha : 2alpha = y)}";
80 n = snprintf(filename, sizeof(filename),
81 "%s/test_inputs/set.omega", srcdir);
82 assert(n < sizeof(filename));
83 input = fopen(filename, "r");
84 assert(input);
86 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
87 bset2 = isl_basic_set_read_from_str(ctx, str, 0);
89 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
91 isl_basic_set_free(bset1);
92 isl_basic_set_free(bset2);
94 fclose(input);
97 void test_bounded(struct isl_ctx *ctx)
99 isl_set *set;
100 int bounded;
102 set = isl_set_read_from_str(ctx, "[n] -> {[i] : 0 <= i <= n }", -1);
103 bounded = isl_set_is_bounded(set);
104 assert(bounded);
105 isl_set_free(set);
107 set = isl_set_read_from_str(ctx, "{[n, i] : 0 <= i <= n }", -1);
108 bounded = isl_set_is_bounded(set);
109 assert(!bounded);
110 isl_set_free(set);
112 set = isl_set_read_from_str(ctx, "[n] -> {[i] : i <= n }", -1);
113 bounded = isl_set_is_bounded(set);
114 assert(!bounded);
115 isl_set_free(set);
118 /* Construct the basic set { [i] : 5 <= i <= N } */
119 void test_construction(struct isl_ctx *ctx)
121 isl_int v;
122 struct isl_dim *dim;
123 struct isl_basic_set *bset;
124 struct isl_constraint *c;
126 isl_int_init(v);
128 dim = isl_dim_set_alloc(ctx, 1, 1);
129 bset = isl_basic_set_universe(dim);
131 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
132 isl_int_set_si(v, -1);
133 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
134 isl_int_set_si(v, 1);
135 isl_constraint_set_coefficient(c, isl_dim_param, 0, v);
136 bset = isl_basic_set_add_constraint(bset, c);
138 c = isl_inequality_alloc(isl_basic_set_get_dim(bset));
139 isl_int_set_si(v, 1);
140 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
141 isl_int_set_si(v, -5);
142 isl_constraint_set_constant(c, v);
143 bset = isl_basic_set_add_constraint(bset, c);
145 isl_basic_set_free(bset);
147 isl_int_clear(v);
150 void test_dim(struct isl_ctx *ctx)
152 const char *str;
153 isl_map *map1, *map2;
155 map1 = isl_map_read_from_str(ctx,
156 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
157 map1 = isl_map_add_dims(map1, isl_dim_in, 1);
158 map2 = isl_map_read_from_str(ctx,
159 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
160 assert(isl_map_is_equal(map1, map2));
161 isl_map_free(map2);
163 map1 = isl_map_project_out(map1, isl_dim_in, 0, 1);
164 map2 = isl_map_read_from_str(ctx, "[n] -> { [i] -> [j] : n >= 0 }", -1);
165 assert(isl_map_is_equal(map1, map2));
167 isl_map_free(map1);
168 isl_map_free(map2);
170 str = "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
171 map1 = isl_map_read_from_str(ctx, str, -1);
172 str = "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
173 map2 = isl_map_read_from_str(ctx, str, -1);
174 map1 = isl_map_move_dims(map1, isl_dim_out, 0, isl_dim_param, 0, 1);
175 assert(isl_map_is_equal(map1, map2));
177 isl_map_free(map1);
178 isl_map_free(map2);
181 void test_div(struct isl_ctx *ctx)
183 isl_int v;
184 int pos;
185 struct isl_dim *dim;
186 struct isl_div *div;
187 struct isl_basic_set *bset;
188 struct isl_constraint *c;
190 isl_int_init(v);
192 /* test 1 */
193 dim = isl_dim_set_alloc(ctx, 0, 1);
194 bset = isl_basic_set_universe(dim);
196 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
197 isl_int_set_si(v, -1);
198 isl_constraint_set_constant(c, v);
199 isl_int_set_si(v, 1);
200 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
201 div = isl_div_alloc(isl_basic_set_get_dim(bset));
202 c = isl_constraint_add_div(c, div, &pos);
203 isl_int_set_si(v, 3);
204 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
205 bset = isl_basic_set_add_constraint(bset, c);
207 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
208 isl_int_set_si(v, 1);
209 isl_constraint_set_constant(c, v);
210 isl_int_set_si(v, -1);
211 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
212 div = isl_div_alloc(isl_basic_set_get_dim(bset));
213 c = isl_constraint_add_div(c, div, &pos);
214 isl_int_set_si(v, 3);
215 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
216 bset = isl_basic_set_add_constraint(bset, c);
218 assert(bset && bset->n_div == 1);
219 isl_basic_set_free(bset);
221 /* test 2 */
222 dim = isl_dim_set_alloc(ctx, 0, 1);
223 bset = isl_basic_set_universe(dim);
225 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
226 isl_int_set_si(v, 1);
227 isl_constraint_set_constant(c, v);
228 isl_int_set_si(v, -1);
229 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
230 div = isl_div_alloc(isl_basic_set_get_dim(bset));
231 c = isl_constraint_add_div(c, div, &pos);
232 isl_int_set_si(v, 3);
233 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
234 bset = isl_basic_set_add_constraint(bset, c);
236 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
237 isl_int_set_si(v, -1);
238 isl_constraint_set_constant(c, v);
239 isl_int_set_si(v, 1);
240 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
241 div = isl_div_alloc(isl_basic_set_get_dim(bset));
242 c = isl_constraint_add_div(c, div, &pos);
243 isl_int_set_si(v, 3);
244 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
245 bset = isl_basic_set_add_constraint(bset, c);
247 assert(bset && bset->n_div == 1);
248 isl_basic_set_free(bset);
250 /* test 3 */
251 dim = isl_dim_set_alloc(ctx, 0, 1);
252 bset = isl_basic_set_universe(dim);
254 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
255 isl_int_set_si(v, 1);
256 isl_constraint_set_constant(c, v);
257 isl_int_set_si(v, -1);
258 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
259 div = isl_div_alloc(isl_basic_set_get_dim(bset));
260 c = isl_constraint_add_div(c, div, &pos);
261 isl_int_set_si(v, 3);
262 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
263 bset = isl_basic_set_add_constraint(bset, c);
265 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
266 isl_int_set_si(v, -3);
267 isl_constraint_set_constant(c, v);
268 isl_int_set_si(v, 1);
269 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
270 div = isl_div_alloc(isl_basic_set_get_dim(bset));
271 c = isl_constraint_add_div(c, div, &pos);
272 isl_int_set_si(v, 4);
273 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
274 bset = isl_basic_set_add_constraint(bset, c);
276 assert(bset && bset->n_div == 1);
277 isl_basic_set_free(bset);
279 /* test 4 */
280 dim = isl_dim_set_alloc(ctx, 0, 1);
281 bset = isl_basic_set_universe(dim);
283 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
284 isl_int_set_si(v, 2);
285 isl_constraint_set_constant(c, v);
286 isl_int_set_si(v, -1);
287 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
288 div = isl_div_alloc(isl_basic_set_get_dim(bset));
289 c = isl_constraint_add_div(c, div, &pos);
290 isl_int_set_si(v, 3);
291 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
292 bset = isl_basic_set_add_constraint(bset, c);
294 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
295 isl_int_set_si(v, -1);
296 isl_constraint_set_constant(c, v);
297 isl_int_set_si(v, 1);
298 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
299 div = isl_div_alloc(isl_basic_set_get_dim(bset));
300 c = isl_constraint_add_div(c, div, &pos);
301 isl_int_set_si(v, 6);
302 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
303 bset = isl_basic_set_add_constraint(bset, c);
305 assert(isl_basic_set_is_empty(bset));
306 isl_basic_set_free(bset);
308 /* test 5 */
309 dim = isl_dim_set_alloc(ctx, 0, 2);
310 bset = isl_basic_set_universe(dim);
312 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
313 isl_int_set_si(v, -1);
314 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
315 div = isl_div_alloc(isl_basic_set_get_dim(bset));
316 c = isl_constraint_add_div(c, div, &pos);
317 isl_int_set_si(v, 3);
318 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
319 bset = isl_basic_set_add_constraint(bset, c);
321 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
322 isl_int_set_si(v, 1);
323 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
324 isl_int_set_si(v, -3);
325 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
326 bset = isl_basic_set_add_constraint(bset, c);
328 assert(bset && bset->n_div == 0);
329 isl_basic_set_free(bset);
331 /* test 6 */
332 dim = isl_dim_set_alloc(ctx, 0, 2);
333 bset = isl_basic_set_universe(dim);
335 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
336 isl_int_set_si(v, -1);
337 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
338 div = isl_div_alloc(isl_basic_set_get_dim(bset));
339 c = isl_constraint_add_div(c, div, &pos);
340 isl_int_set_si(v, 6);
341 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
342 bset = isl_basic_set_add_constraint(bset, c);
344 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
345 isl_int_set_si(v, 1);
346 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
347 isl_int_set_si(v, -3);
348 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
349 bset = isl_basic_set_add_constraint(bset, c);
351 assert(bset && bset->n_div == 1);
352 isl_basic_set_free(bset);
354 /* test 7 */
355 /* This test is a bit tricky. We set up an equality
356 * a + 3b + 3c = 6 e0
357 * Normalization of divs creates _two_ divs
358 * a = 3 e0
359 * c - b - e0 = 2 e1
360 * Afterwards e0 is removed again because it has coefficient -1
361 * and we end up with the original equality and div again.
362 * Perhaps we can avoid the introduction of this temporary div.
364 dim = isl_dim_set_alloc(ctx, 0, 3);
365 bset = isl_basic_set_universe(dim);
367 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
368 isl_int_set_si(v, -1);
369 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
370 isl_int_set_si(v, -3);
371 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
372 isl_int_set_si(v, -3);
373 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
374 div = isl_div_alloc(isl_basic_set_get_dim(bset));
375 c = isl_constraint_add_div(c, div, &pos);
376 isl_int_set_si(v, 6);
377 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
378 bset = isl_basic_set_add_constraint(bset, c);
380 /* Test disabled for now */
382 assert(bset && bset->n_div == 1);
384 isl_basic_set_free(bset);
386 /* test 8 */
387 dim = isl_dim_set_alloc(ctx, 0, 4);
388 bset = isl_basic_set_universe(dim);
390 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
391 isl_int_set_si(v, -1);
392 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
393 isl_int_set_si(v, -3);
394 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
395 isl_int_set_si(v, -3);
396 isl_constraint_set_coefficient(c, isl_dim_set, 3, v);
397 div = isl_div_alloc(isl_basic_set_get_dim(bset));
398 c = isl_constraint_add_div(c, div, &pos);
399 isl_int_set_si(v, 6);
400 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
401 bset = isl_basic_set_add_constraint(bset, c);
403 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
404 isl_int_set_si(v, -1);
405 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
406 isl_int_set_si(v, 1);
407 isl_constraint_set_coefficient(c, isl_dim_set, 2, v);
408 isl_int_set_si(v, 1);
409 isl_constraint_set_constant(c, v);
410 bset = isl_basic_set_add_constraint(bset, c);
412 /* Test disabled for now */
414 assert(bset && bset->n_div == 1);
416 isl_basic_set_free(bset);
418 /* test 9 */
419 dim = isl_dim_set_alloc(ctx, 0, 2);
420 bset = isl_basic_set_universe(dim);
422 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
423 isl_int_set_si(v, 1);
424 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
425 isl_int_set_si(v, -1);
426 isl_constraint_set_coefficient(c, isl_dim_set, 1, v);
427 div = isl_div_alloc(isl_basic_set_get_dim(bset));
428 c = isl_constraint_add_div(c, div, &pos);
429 isl_int_set_si(v, -2);
430 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
431 bset = isl_basic_set_add_constraint(bset, c);
433 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
434 isl_int_set_si(v, -1);
435 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
436 div = isl_div_alloc(isl_basic_set_get_dim(bset));
437 c = isl_constraint_add_div(c, div, &pos);
438 isl_int_set_si(v, 3);
439 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
440 isl_int_set_si(v, 2);
441 isl_constraint_set_constant(c, v);
442 bset = isl_basic_set_add_constraint(bset, c);
444 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
446 assert(!isl_basic_set_is_empty(bset));
448 isl_basic_set_free(bset);
450 /* test 10 */
451 dim = isl_dim_set_alloc(ctx, 0, 2);
452 bset = isl_basic_set_universe(dim);
454 c = isl_equality_alloc(isl_basic_set_get_dim(bset));
455 isl_int_set_si(v, 1);
456 isl_constraint_set_coefficient(c, isl_dim_set, 0, v);
457 div = isl_div_alloc(isl_basic_set_get_dim(bset));
458 c = isl_constraint_add_div(c, div, &pos);
459 isl_int_set_si(v, -2);
460 isl_constraint_set_coefficient(c, isl_dim_div, pos, v);
461 bset = isl_basic_set_add_constraint(bset, c);
463 bset = isl_basic_set_fix_si(bset, isl_dim_set, 0, 2);
465 isl_basic_set_free(bset);
467 isl_int_clear(v);
470 void test_application_case(struct isl_ctx *ctx, const char *name)
472 char filename[PATH_MAX];
473 FILE *input;
474 int n;
475 struct isl_basic_set *bset1, *bset2;
476 struct isl_basic_map *bmap;
478 n = snprintf(filename, sizeof(filename),
479 "%s/test_inputs/%s.omega", srcdir, name);
480 assert(n < sizeof(filename));
481 input = fopen(filename, "r");
482 assert(input);
484 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
485 bmap = isl_basic_map_read_from_file(ctx, input, 0);
487 bset1 = isl_basic_set_apply(bset1, bmap);
489 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
491 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
493 isl_basic_set_free(bset1);
494 isl_basic_set_free(bset2);
496 fclose(input);
499 void test_application(struct isl_ctx *ctx)
501 test_application_case(ctx, "application");
502 test_application_case(ctx, "application2");
505 void test_affine_hull_case(struct isl_ctx *ctx, const char *name)
507 char filename[PATH_MAX];
508 FILE *input;
509 int n;
510 struct isl_basic_set *bset1, *bset2;
512 n = snprintf(filename, sizeof(filename),
513 "%s/test_inputs/%s.polylib", srcdir, name);
514 assert(n < sizeof(filename));
515 input = fopen(filename, "r");
516 assert(input);
518 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
519 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
521 bset1 = isl_basic_set_affine_hull(bset1);
523 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
525 isl_basic_set_free(bset1);
526 isl_basic_set_free(bset2);
528 fclose(input);
531 void test_affine_hull(struct isl_ctx *ctx)
533 test_affine_hull_case(ctx, "affine2");
534 test_affine_hull_case(ctx, "affine");
535 test_affine_hull_case(ctx, "affine3");
538 void test_convex_hull_case(struct isl_ctx *ctx, const char *name)
540 char filename[PATH_MAX];
541 FILE *input;
542 int n;
543 struct isl_basic_set *bset1, *bset2;
544 struct isl_set *set;
546 n = snprintf(filename, sizeof(filename),
547 "%s/test_inputs/%s.polylib", srcdir, name);
548 assert(n < sizeof(filename));
549 input = fopen(filename, "r");
550 assert(input);
552 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
553 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
555 set = isl_basic_set_union(bset1, bset2);
556 bset1 = isl_set_convex_hull(set);
558 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
560 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
562 isl_basic_set_free(bset1);
563 isl_basic_set_free(bset2);
565 fclose(input);
568 void test_convex_hull(struct isl_ctx *ctx)
570 const char *str1, *str2;
571 isl_set *set1, *set2;
573 test_convex_hull_case(ctx, "convex0");
574 test_convex_hull_case(ctx, "convex1");
575 test_convex_hull_case(ctx, "convex2");
576 test_convex_hull_case(ctx, "convex3");
577 test_convex_hull_case(ctx, "convex4");
578 test_convex_hull_case(ctx, "convex5");
579 test_convex_hull_case(ctx, "convex6");
580 test_convex_hull_case(ctx, "convex7");
581 test_convex_hull_case(ctx, "convex8");
582 test_convex_hull_case(ctx, "convex9");
583 test_convex_hull_case(ctx, "convex10");
584 test_convex_hull_case(ctx, "convex11");
585 test_convex_hull_case(ctx, "convex12");
586 test_convex_hull_case(ctx, "convex13");
587 test_convex_hull_case(ctx, "convex14");
588 test_convex_hull_case(ctx, "convex15");
590 str1 = "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
591 "(i0 = 1 and i1 = 0 and i2 = 1) or "
592 "(i0 = 0 and i1 = 0 and i2 = 0) }";
593 str2 = "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
594 set1 = isl_set_read_from_str(ctx, str1, -1);
595 set2 = isl_set_read_from_str(ctx, str2, -1);
596 set1 = isl_set_from_basic_set(isl_set_convex_hull(set1));
597 assert(isl_set_is_equal(set1, set2));
598 isl_set_free(set1);
599 isl_set_free(set2);
602 void test_gist_case(struct isl_ctx *ctx, const char *name)
604 char filename[PATH_MAX];
605 FILE *input;
606 int n;
607 struct isl_basic_set *bset1, *bset2;
609 n = snprintf(filename, sizeof(filename),
610 "%s/test_inputs/%s.polylib", srcdir, name);
611 assert(n < sizeof(filename));
612 input = fopen(filename, "r");
613 assert(input);
615 bset1 = isl_basic_set_read_from_file(ctx, input, 0);
616 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
618 bset1 = isl_basic_set_gist(bset1, bset2);
620 bset2 = isl_basic_set_read_from_file(ctx, input, 0);
622 assert(isl_basic_set_is_equal(bset1, bset2) == 1);
624 isl_basic_set_free(bset1);
625 isl_basic_set_free(bset2);
627 fclose(input);
630 void test_gist(struct isl_ctx *ctx)
632 test_gist_case(ctx, "gist1");
635 void test_coalesce_set(isl_ctx *ctx, const char *str, int check_one)
637 isl_set *set, *set2;
639 set = isl_set_read_from_str(ctx, str, -1);
640 set = isl_set_coalesce(set);
641 set2 = isl_set_read_from_str(ctx, str, -1);
642 assert(isl_set_is_equal(set, set2));
643 if (check_one)
644 assert(set && set->n == 1);
645 isl_set_free(set);
646 isl_set_free(set2);
649 void test_coalesce(struct isl_ctx *ctx)
651 const char *str;
652 struct isl_set *set, *set2;
653 struct isl_map *map, *map2;
655 set = isl_set_read_from_str(ctx,
656 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
657 "y >= x & x >= 2 & 5 >= y }", -1);
658 set = isl_set_coalesce(set);
659 assert(set && set->n == 1);
660 isl_set_free(set);
662 set = isl_set_read_from_str(ctx,
663 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
664 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
665 set = isl_set_coalesce(set);
666 assert(set && set->n == 1);
667 isl_set_free(set);
669 set = isl_set_read_from_str(ctx,
670 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
671 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
672 set = isl_set_coalesce(set);
673 assert(set && set->n == 2);
674 isl_set_free(set);
676 set = isl_set_read_from_str(ctx,
677 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
678 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
679 set = isl_set_coalesce(set);
680 assert(set && set->n == 1);
681 isl_set_free(set);
683 set = isl_set_read_from_str(ctx,
684 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
685 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
686 set = isl_set_coalesce(set);
687 assert(set && set->n == 2);
688 isl_set_free(set);
690 set = isl_set_read_from_str(ctx,
691 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
692 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
693 set = isl_set_coalesce(set);
694 assert(set && set->n == 2);
695 isl_set_free(set);
697 set = isl_set_read_from_str(ctx,
698 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
699 "y >= 0 & x = 6 & y <= 6}", -1);
700 set = isl_set_coalesce(set);
701 assert(set && set->n == 1);
702 isl_set_free(set);
704 set = isl_set_read_from_str(ctx,
705 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
706 "y >= 0 & x = 7 & y <= 6}", -1);
707 set = isl_set_coalesce(set);
708 assert(set && set->n == 2);
709 isl_set_free(set);
711 set = isl_set_read_from_str(ctx,
712 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
713 "y >= 0 & x = 6 & y <= 5}", -1);
714 set = isl_set_coalesce(set);
715 assert(set && set->n == 1);
716 set2 = isl_set_read_from_str(ctx,
717 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
718 "y >= 0 & x = 6 & y <= 5}", -1);
719 assert(isl_set_is_equal(set, set2));
720 isl_set_free(set);
721 isl_set_free(set2);
723 set = isl_set_read_from_str(ctx,
724 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
725 "y >= 0 & x = 6 & y <= 7}", -1);
726 set = isl_set_coalesce(set);
727 assert(set && set->n == 2);
728 isl_set_free(set);
730 set = isl_set_read_from_str(ctx,
731 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
732 set = isl_set_coalesce(set);
733 assert(set && set->n == 1);
734 set2 = isl_set_read_from_str(ctx,
735 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
736 assert(isl_set_is_equal(set, set2));
737 isl_set_free(set);
738 isl_set_free(set2);
740 set = isl_set_read_from_str(ctx,
741 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
742 set = isl_set_coalesce(set);
743 set2 = isl_set_read_from_str(ctx,
744 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
745 assert(isl_set_is_equal(set, set2));
746 isl_set_free(set);
747 isl_set_free(set2);
749 set = isl_set_read_from_str(ctx,
750 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
751 "2 <= i and i <= n }", -1);
752 set = isl_set_coalesce(set);
753 assert(set && set->n == 1);
754 set2 = isl_set_read_from_str(ctx,
755 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
756 "2 <= i and i <= n }", -1);
757 assert(isl_set_is_equal(set, set2));
758 isl_set_free(set);
759 isl_set_free(set2);
761 map = isl_map_read_from_str(ctx,
762 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
763 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
764 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
765 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
766 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
767 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
768 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
769 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
770 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
771 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
772 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
773 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
774 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
775 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
776 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
777 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
778 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
779 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
780 map = isl_map_coalesce(map);
781 map2 = isl_map_read_from_str(ctx,
782 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
783 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
784 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
785 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
786 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
787 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
788 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
789 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
790 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
791 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
792 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
793 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
794 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
795 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
796 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
797 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
798 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
799 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
800 assert(isl_map_is_equal(map, map2));
801 isl_map_free(map);
802 isl_map_free(map2);
804 str = "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
805 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
806 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
807 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
808 map = isl_map_read_from_str(ctx, str, -1);
809 map = isl_map_coalesce(map);
810 map2 = isl_map_read_from_str(ctx, str, -1);
811 assert(isl_map_is_equal(map, map2));
812 isl_map_free(map);
813 isl_map_free(map2);
815 str = "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
816 "[o0, o1, o2, o3, o4, o5, o6] : "
817 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
818 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
819 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
820 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
821 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
822 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
823 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
824 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
825 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
826 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
827 "o6 >= i3 + i6 - o3 and M >= 0 and "
828 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
829 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
830 map = isl_map_read_from_str(ctx, str, -1);
831 map = isl_map_coalesce(map);
832 map2 = isl_map_read_from_str(ctx, str, -1);
833 assert(isl_map_is_equal(map, map2));
834 isl_map_free(map);
835 isl_map_free(map2);
837 str = "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
838 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
839 "(o0 = 0 and M >= 2 and N >= 3) or "
840 "(M = 0 and o0 = 0 and N >= 3) }";
841 map = isl_map_read_from_str(ctx, str, -1);
842 map = isl_map_coalesce(map);
843 map2 = isl_map_read_from_str(ctx, str, -1);
844 assert(isl_map_is_equal(map, map2));
845 isl_map_free(map);
846 isl_map_free(map2);
848 str = "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
849 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
850 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
851 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
852 map = isl_map_read_from_str(ctx, str, -1);
853 map = isl_map_coalesce(map);
854 map2 = isl_map_read_from_str(ctx, str, -1);
855 assert(isl_map_is_equal(map, map2));
856 isl_map_free(map);
857 isl_map_free(map2);
859 test_coalesce_set(ctx,
860 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
861 "(i1 = M and M >= 1) }", 0);
862 test_coalesce_set(ctx,
863 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
864 test_coalesce_set(ctx,
865 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
866 "(y = 3 and x = 1) }", 1);
867 test_coalesce_set(ctx,
868 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
869 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
870 "i1 <= M and i3 <= M and i4 <= M) or "
871 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
872 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
873 "i4 <= -1 + M) }", 1);
874 test_coalesce_set(ctx,
875 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
876 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
877 test_coalesce_set(ctx,
878 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
879 "-x - y + 1 >= 0 and -3 <= z <= 3;"
880 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
881 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
882 test_coalesce_set(ctx,
883 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
884 test_coalesce_set(ctx, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
885 test_coalesce_set(ctx,
886 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
887 test_coalesce_set(ctx, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
890 void test_closure(struct isl_ctx *ctx)
892 const char *str;
893 isl_set *dom;
894 isl_map *up, *right;
895 isl_map *map, *map2;
896 int exact;
898 /* COCOA example 1 */
899 map = isl_map_read_from_str(ctx,
900 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
901 "1 <= i and i < n and 1 <= j and j < n or "
902 "i2 = i + 1 and j2 = j - 1 and "
903 "1 <= i and i < n and 2 <= j and j <= n }", -1);
904 map = isl_map_power(map, 1, &exact);
905 assert(exact);
906 isl_map_free(map);
908 /* COCOA example 1 */
909 map = isl_map_read_from_str(ctx,
910 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
911 "1 <= i and i < n and 1 <= j and j < n or "
912 "i2 = i + 1 and j2 = j - 1 and "
913 "1 <= i and i < n and 2 <= j and j <= n }", -1);
914 map = isl_map_transitive_closure(map, &exact);
915 assert(exact);
916 map2 = isl_map_read_from_str(ctx,
917 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
918 "1 <= i and i < n and 1 <= j and j <= n and "
919 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
920 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
921 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
922 assert(isl_map_is_equal(map, map2));
923 isl_map_free(map2);
924 isl_map_free(map);
926 map = isl_map_read_from_str(ctx,
927 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
928 " 0 <= y and y <= n }", -1);
929 map = isl_map_transitive_closure(map, &exact);
930 map2 = isl_map_read_from_str(ctx,
931 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
932 " 0 <= y and y <= n }", -1);
933 assert(isl_map_is_equal(map, map2));
934 isl_map_free(map2);
935 isl_map_free(map);
937 /* COCOA example 2 */
938 map = isl_map_read_from_str(ctx,
939 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
940 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
941 "i2 = i + 2 and j2 = j - 2 and "
942 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
943 map = isl_map_transitive_closure(map, &exact);
944 assert(exact);
945 map2 = isl_map_read_from_str(ctx,
946 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
947 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
948 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
949 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
950 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
951 assert(isl_map_is_equal(map, map2));
952 isl_map_free(map);
953 isl_map_free(map2);
955 /* COCOA Fig.2 left */
956 map = isl_map_read_from_str(ctx,
957 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
958 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
959 "j <= n or "
960 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
961 "j <= 2 i - 3 and j <= n - 2 or "
962 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
963 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
964 map = isl_map_transitive_closure(map, &exact);
965 assert(exact);
966 isl_map_free(map);
968 /* COCOA Fig.2 right */
969 map = isl_map_read_from_str(ctx,
970 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
971 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
972 "j <= n or "
973 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
974 "j <= 2 i - 4 and j <= n - 3 or "
975 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
976 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
977 map = isl_map_power(map, 1, &exact);
978 assert(exact);
979 isl_map_free(map);
981 /* COCOA Fig.2 right */
982 map = isl_map_read_from_str(ctx,
983 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
984 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
985 "j <= n or "
986 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
987 "j <= 2 i - 4 and j <= n - 3 or "
988 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
989 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
990 map = isl_map_transitive_closure(map, &exact);
991 assert(exact);
992 map2 = isl_map_read_from_str(ctx,
993 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
994 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
995 "j <= n and 3 + i + 2 j <= 3 n and "
996 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
997 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
998 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
999 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1000 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1001 assert(isl_map_is_equal(map, map2));
1002 isl_map_free(map2);
1003 isl_map_free(map);
1005 /* COCOA Fig.1 right */
1006 dom = isl_set_read_from_str(ctx,
1007 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1008 "2 x - 3 y + 3 >= 0 }", -1);
1009 right = isl_map_read_from_str(ctx,
1010 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1011 up = isl_map_read_from_str(ctx,
1012 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1013 right = isl_map_intersect_domain(right, isl_set_copy(dom));
1014 right = isl_map_intersect_range(right, isl_set_copy(dom));
1015 up = isl_map_intersect_domain(up, isl_set_copy(dom));
1016 up = isl_map_intersect_range(up, dom);
1017 map = isl_map_union(up, right);
1018 map = isl_map_transitive_closure(map, &exact);
1019 assert(exact);
1020 map2 = isl_map_read_from_str(ctx,
1021 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1022 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1023 assert(isl_map_is_equal(map, map2));
1024 isl_map_free(map2);
1025 isl_map_free(map);
1027 /* COCOA Theorem 1 counter example */
1028 map = isl_map_read_from_str(ctx,
1029 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1030 "i2 = 1 and j2 = j or "
1031 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1032 map = isl_map_transitive_closure(map, &exact);
1033 assert(exact);
1034 isl_map_free(map);
1036 map = isl_map_read_from_str(ctx,
1037 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1038 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1039 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1040 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1041 map = isl_map_transitive_closure(map, &exact);
1042 assert(exact);
1043 isl_map_free(map);
1045 /* Kelly et al 1996, fig 12 */
1046 map = isl_map_read_from_str(ctx,
1047 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1048 "1 <= i,j,j+1 <= n or "
1049 "j = n and j2 = 1 and i2 = i + 1 and "
1050 "1 <= i,i+1 <= n }", -1);
1051 map = isl_map_transitive_closure(map, &exact);
1052 assert(exact);
1053 map2 = isl_map_read_from_str(ctx,
1054 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1055 "1 <= i <= n and i = i2 or "
1056 "1 <= i < i2 <= n and 1 <= j <= n and "
1057 "1 <= j2 <= n }", -1);
1058 assert(isl_map_is_equal(map, map2));
1059 isl_map_free(map2);
1060 isl_map_free(map);
1062 /* Omega's closure4 */
1063 map = isl_map_read_from_str(ctx,
1064 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1065 "1 <= x,y <= 10 or "
1066 "x2 = x + 1 and y2 = y and "
1067 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1068 map = isl_map_transitive_closure(map, &exact);
1069 assert(exact);
1070 isl_map_free(map);
1072 map = isl_map_read_from_str(ctx,
1073 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1074 map = isl_map_transitive_closure(map, &exact);
1075 assert(!exact);
1076 map2 = isl_map_read_from_str(ctx,
1077 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1078 assert(isl_map_is_equal(map, map2));
1079 isl_map_free(map);
1080 isl_map_free(map2);
1082 str = "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1083 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1084 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1085 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1086 map = isl_map_read_from_str(ctx, str, -1);
1087 map = isl_map_transitive_closure(map, &exact);
1088 assert(exact);
1089 map2 = isl_map_read_from_str(ctx, str, -1);
1090 assert(isl_map_is_equal(map, map2));
1091 isl_map_free(map);
1092 isl_map_free(map2);
1094 str = "{[0] -> [1]; [2] -> [3]}";
1095 map = isl_map_read_from_str(ctx, str, -1);
1096 map = isl_map_transitive_closure(map, &exact);
1097 assert(exact);
1098 map2 = isl_map_read_from_str(ctx, str, -1);
1099 assert(isl_map_is_equal(map, map2));
1100 isl_map_free(map);
1101 isl_map_free(map2);
1104 void test_lex(struct isl_ctx *ctx)
1106 isl_dim *dim;
1107 isl_map *map;
1109 dim = isl_dim_alloc(ctx, 0, 0, 0);
1110 map = isl_map_lex_le(dim);
1111 assert(!isl_map_is_empty(map));
1112 isl_map_free(map);
1115 void test_lexmin(struct isl_ctx *ctx)
1117 const char *str;
1118 isl_map *map;
1119 isl_set *set;
1120 isl_set *set2;
1122 str = "[p0, p1] -> { [] -> [] : "
1123 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1124 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1125 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1126 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1127 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1128 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1129 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1130 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1131 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1132 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1133 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1134 map = isl_map_read_from_str(ctx, str, -1);
1135 map = isl_map_lexmin(map);
1136 isl_map_free(map);
1138 str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1139 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1140 set = isl_set_read_from_str(ctx, str, -1);
1141 set = isl_set_lexmax(set);
1142 str = "[C] -> { [obj,a,b,c] : C = 8 }";
1143 set2 = isl_set_read_from_str(ctx, str, -1);
1144 set = isl_set_intersect(set, set2);
1145 assert(!isl_set_is_empty(set));
1146 isl_set_free(set);
1149 struct must_may {
1150 isl_map *must;
1151 isl_map *may;
1154 static int collect_must_may(__isl_take isl_map *dep, int must,
1155 void *dep_user, void *user)
1157 struct must_may *mm = (struct must_may *)user;
1159 if (must)
1160 mm->must = isl_map_union(mm->must, dep);
1161 else
1162 mm->may = isl_map_union(mm->may, dep);
1164 return 0;
1167 static int common_space(void *first, void *second)
1169 int depth = *(int *)first;
1170 return 2 * depth;
1173 static int map_is_equal(__isl_keep isl_map *map, const char *str)
1175 isl_map *map2;
1176 int equal;
1178 if (!map)
1179 return -1;
1181 map2 = isl_map_read_from_str(map->ctx, str, -1);
1182 equal = isl_map_is_equal(map, map2);
1183 isl_map_free(map2);
1185 return equal;
1188 void test_dep(struct isl_ctx *ctx)
1190 const char *str;
1191 isl_dim *dim;
1192 isl_map *map;
1193 isl_access_info *ai;
1194 isl_flow *flow;
1195 int depth;
1196 struct must_may mm;
1198 depth = 3;
1200 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1201 map = isl_map_read_from_str(ctx, str, -1);
1202 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1204 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1205 map = isl_map_read_from_str(ctx, str, -1);
1206 ai = isl_access_info_add_source(ai, map, 1, &depth);
1208 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1209 map = isl_map_read_from_str(ctx, str, -1);
1210 ai = isl_access_info_add_source(ai, map, 1, &depth);
1212 flow = isl_access_info_compute_flow(ai);
1213 dim = isl_dim_alloc(ctx, 0, 3, 3);
1214 mm.must = isl_map_empty(isl_dim_copy(dim));
1215 mm.may = isl_map_empty(dim);
1217 isl_flow_foreach(flow, collect_must_may, &mm);
1219 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1220 " [1,10,0] -> [2,5,0] }";
1221 assert(map_is_equal(mm.must, str));
1222 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1223 assert(map_is_equal(mm.may, str));
1225 isl_map_free(mm.must);
1226 isl_map_free(mm.may);
1227 isl_flow_free(flow);
1230 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1231 map = isl_map_read_from_str(ctx, str, -1);
1232 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1234 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1235 map = isl_map_read_from_str(ctx, str, -1);
1236 ai = isl_access_info_add_source(ai, map, 1, &depth);
1238 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1239 map = isl_map_read_from_str(ctx, str, -1);
1240 ai = isl_access_info_add_source(ai, map, 0, &depth);
1242 flow = isl_access_info_compute_flow(ai);
1243 dim = isl_dim_alloc(ctx, 0, 3, 3);
1244 mm.must = isl_map_empty(isl_dim_copy(dim));
1245 mm.may = isl_map_empty(dim);
1247 isl_flow_foreach(flow, collect_must_may, &mm);
1249 str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1250 assert(map_is_equal(mm.must, str));
1251 str = "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1252 assert(map_is_equal(mm.may, str));
1254 isl_map_free(mm.must);
1255 isl_map_free(mm.may);
1256 isl_flow_free(flow);
1259 str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1260 map = isl_map_read_from_str(ctx, str, -1);
1261 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1263 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1264 map = isl_map_read_from_str(ctx, str, -1);
1265 ai = isl_access_info_add_source(ai, map, 0, &depth);
1267 str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1268 map = isl_map_read_from_str(ctx, str, -1);
1269 ai = isl_access_info_add_source(ai, map, 0, &depth);
1271 flow = isl_access_info_compute_flow(ai);
1272 dim = isl_dim_alloc(ctx, 0, 3, 3);
1273 mm.must = isl_map_empty(isl_dim_copy(dim));
1274 mm.may = isl_map_empty(dim);
1276 isl_flow_foreach(flow, collect_must_may, &mm);
1278 str = "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1279 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1280 assert(map_is_equal(mm.may, str));
1281 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1282 assert(map_is_equal(mm.must, str));
1284 isl_map_free(mm.must);
1285 isl_map_free(mm.may);
1286 isl_flow_free(flow);
1289 str = "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1290 map = isl_map_read_from_str(ctx, str, -1);
1291 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1293 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1294 map = isl_map_read_from_str(ctx, str, -1);
1295 ai = isl_access_info_add_source(ai, map, 0, &depth);
1297 str = "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1298 map = isl_map_read_from_str(ctx, str, -1);
1299 ai = isl_access_info_add_source(ai, map, 0, &depth);
1301 flow = isl_access_info_compute_flow(ai);
1302 dim = isl_dim_alloc(ctx, 0, 3, 3);
1303 mm.must = isl_map_empty(isl_dim_copy(dim));
1304 mm.may = isl_map_empty(dim);
1306 isl_flow_foreach(flow, collect_must_may, &mm);
1308 str = "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1309 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1310 assert(map_is_equal(mm.may, str));
1311 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1312 assert(map_is_equal(mm.must, str));
1314 isl_map_free(mm.must);
1315 isl_map_free(mm.may);
1316 isl_flow_free(flow);
1319 str = "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1320 map = isl_map_read_from_str(ctx, str, -1);
1321 ai = isl_access_info_alloc(map, &depth, &common_space, 2);
1323 str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1324 map = isl_map_read_from_str(ctx, str, -1);
1325 ai = isl_access_info_add_source(ai, map, 0, &depth);
1327 str = "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1328 map = isl_map_read_from_str(ctx, str, -1);
1329 ai = isl_access_info_add_source(ai, map, 0, &depth);
1331 flow = isl_access_info_compute_flow(ai);
1332 dim = isl_dim_alloc(ctx, 0, 3, 3);
1333 mm.must = isl_map_empty(isl_dim_copy(dim));
1334 mm.may = isl_map_empty(dim);
1336 isl_flow_foreach(flow, collect_must_may, &mm);
1338 str = "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1339 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1340 assert(map_is_equal(mm.may, str));
1341 str = "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1342 assert(map_is_equal(mm.must, str));
1344 isl_map_free(mm.must);
1345 isl_map_free(mm.may);
1346 isl_flow_free(flow);
1349 depth = 5;
1351 str = "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1352 map = isl_map_read_from_str(ctx, str, -1);
1353 ai = isl_access_info_alloc(map, &depth, &common_space, 1);
1355 str = "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1356 map = isl_map_read_from_str(ctx, str, -1);
1357 ai = isl_access_info_add_source(ai, map, 1, &depth);
1359 flow = isl_access_info_compute_flow(ai);
1360 dim = isl_dim_alloc(ctx, 0, 5, 5);
1361 mm.must = isl_map_empty(isl_dim_copy(dim));
1362 mm.may = isl_map_empty(dim);
1364 isl_flow_foreach(flow, collect_must_may, &mm);
1366 str = "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1367 assert(map_is_equal(mm.must, str));
1368 str = "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1369 assert(map_is_equal(mm.may, str));
1371 isl_map_free(mm.must);
1372 isl_map_free(mm.may);
1373 isl_flow_free(flow);
1376 void test_sv(struct isl_ctx *ctx)
1378 const char *str;
1379 isl_map *map;
1381 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1382 map = isl_map_read_from_str(ctx, str, -1);
1383 assert(isl_map_is_single_valued(map));
1384 isl_map_free(map);
1386 str = "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1387 map = isl_map_read_from_str(ctx, str, -1);
1388 assert(!isl_map_is_single_valued(map));
1389 isl_map_free(map);
1392 void test_bijective_case(struct isl_ctx *ctx, const char *str, int bijective)
1394 isl_map *map;
1396 map = isl_map_read_from_str(ctx, str, -1);
1397 if (bijective)
1398 assert(isl_map_is_bijective(map));
1399 else
1400 assert(!isl_map_is_bijective(map));
1401 isl_map_free(map);
1404 void test_bijective(struct isl_ctx *ctx)
1406 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i]}", 0);
1407 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1408 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1409 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1410 test_bijective_case(ctx, "[N,M]->{[i,j] -> [j,i]}", 1);
1411 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i+j]}", 0);
1412 test_bijective_case(ctx, "[N,M]->{[i,j] -> []}", 0);
1413 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1414 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i]}", 0);
1415 test_bijective_case(ctx, "[N,M]->{[i,j] -> [i,i]}", 0);
1416 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,i]}", 0);
1417 test_bijective_case(ctx, "[N,M]->{[i,j] -> [2i,j]}", 1);
1418 test_bijective_case(ctx, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1421 void test_pwqp(struct isl_ctx *ctx)
1423 const char *str;
1424 isl_set *set;
1425 isl_pw_qpolynomial *pwqp1, *pwqp2;
1427 str = "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1428 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1430 pwqp1 = isl_pw_qpolynomial_move_dims(pwqp1, isl_dim_param, 0,
1431 isl_dim_set, 1, 1);
1433 str = "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1434 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1436 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1438 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1440 isl_pw_qpolynomial_free(pwqp1);
1442 str = "{ [i] -> i }";
1443 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1444 str = "{ [k] : exists a : k = 2a }";
1445 set = isl_set_read_from_str(ctx, str, 0);
1446 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1447 str = "{ [i] -> i }";
1448 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1450 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1452 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1454 isl_pw_qpolynomial_free(pwqp1);
1456 str = "{ [i] -> i + [ (i + [i/3])/2 ] }";
1457 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1458 str = "{ [10] }";
1459 set = isl_set_read_from_str(ctx, str, 0);
1460 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1461 str = "{ [i] -> 16 }";
1462 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1464 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1466 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1468 isl_pw_qpolynomial_free(pwqp1);
1470 str = "{ [i] -> ([(i)/2]) }";
1471 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1472 str = "{ [k] : exists a : k = 2a+1 }";
1473 set = isl_set_read_from_str(ctx, str, 0);
1474 pwqp1 = isl_pw_qpolynomial_gist(pwqp1, set);
1475 str = "{ [i] -> -1/2 + 1/2 * i }";
1476 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1478 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1480 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1482 isl_pw_qpolynomial_free(pwqp1);
1484 str = "{ [i] -> ([([i/2] + [i/2])/5]) }";
1485 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1486 str = "{ [i] -> ([(2 * [i/2])/5]) }";
1487 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1489 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1491 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1493 isl_pw_qpolynomial_free(pwqp1);
1495 str = "{ [x] -> ([x/2] + [(x+1)/2]) }";
1496 pwqp1 = isl_pw_qpolynomial_read_from_str(ctx, str);
1497 str = "{ [x] -> x }";
1498 pwqp2 = isl_pw_qpolynomial_read_from_str(ctx, str);
1500 pwqp1 = isl_pw_qpolynomial_sub(pwqp1, pwqp2);
1502 assert(isl_pw_qpolynomial_is_zero(pwqp1));
1504 isl_pw_qpolynomial_free(pwqp1);
1507 void test_split_periods(isl_ctx *ctx)
1509 const char *str;
1510 isl_pw_qpolynomial *pwqp;
1512 str = "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1513 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1514 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1515 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1517 pwqp = isl_pw_qpolynomial_split_periods(pwqp, 2);
1518 assert(pwqp);
1520 isl_pw_qpolynomial_free(pwqp);
1523 void test_union(isl_ctx *ctx)
1525 const char *str;
1526 isl_union_set *uset1, *uset2;
1527 isl_union_map *umap1, *umap2;
1529 str = "{ [i] : 0 <= i <= 1 }";
1530 uset1 = isl_union_set_read_from_str(ctx, str);
1531 str = "{ [1] -> [0] }";
1532 umap1 = isl_union_map_read_from_str(ctx, str);
1534 umap2 = isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1), uset1);
1535 assert(isl_union_map_is_equal(umap1, umap2));
1537 isl_union_map_free(umap1);
1538 isl_union_map_free(umap2);
1540 str = "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1541 umap1 = isl_union_map_read_from_str(ctx, str);
1542 str = "{ A[i]; B[i] }";
1543 uset1 = isl_union_set_read_from_str(ctx, str);
1545 uset2 = isl_union_map_domain(umap1);
1547 assert(isl_union_set_is_equal(uset1, uset2));
1549 isl_union_set_free(uset1);
1550 isl_union_set_free(uset2);
1553 void test_bound(isl_ctx *ctx)
1555 const char *str;
1556 isl_pw_qpolynomial *pwqp;
1557 isl_pw_qpolynomial_fold *pwf;
1559 str = "{ [[a, b, c, d] -> [e]] -> 0 }";
1560 pwqp = isl_pw_qpolynomial_read_from_str(ctx, str);
1561 pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL);
1562 assert(isl_pw_qpolynomial_fold_dim(pwf, isl_dim_set) == 4);
1563 isl_pw_qpolynomial_fold_free(pwf);
1566 void test_lift(isl_ctx *ctx)
1568 const char *str;
1569 isl_basic_map *bmap;
1570 isl_basic_set *bset;
1572 str = "{ [i0] : exists e0 : i0 = 4e0 }";
1573 bset = isl_basic_set_read_from_str(ctx, str, 0);
1574 bset = isl_basic_set_lift(bset);
1575 bmap = isl_basic_map_from_range(bset);
1576 bset = isl_basic_map_domain(bmap);
1577 isl_basic_set_free(bset);
1580 void test_subset(isl_ctx *ctx)
1582 const char *str;
1583 isl_set *set1, *set2;
1585 str = "{ [112, 0] }";
1586 set1 = isl_set_read_from_str(ctx, str, 0);
1587 str = "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1588 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1589 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1590 set2 = isl_set_read_from_str(ctx, str, 0);
1591 assert(isl_set_is_subset(set1, set2));
1592 isl_set_free(set1);
1593 isl_set_free(set2);
1596 int main()
1598 struct isl_ctx *ctx;
1600 srcdir = getenv("srcdir");
1601 assert(srcdir);
1603 ctx = isl_ctx_alloc();
1604 test_subset(ctx);
1605 test_lift(ctx);
1606 test_bound(ctx);
1607 test_union(ctx);
1608 test_split_periods(ctx);
1609 test_parse(ctx);
1610 test_pwqp(ctx);
1611 test_lex(ctx);
1612 test_sv(ctx);
1613 test_bijective(ctx);
1614 test_dep(ctx);
1615 test_read(ctx);
1616 test_bounded(ctx);
1617 test_construction(ctx);
1618 test_dim(ctx);
1619 test_div(ctx);
1620 test_application(ctx);
1621 test_affine_hull(ctx);
1622 test_convex_hull(ctx);
1623 test_gist(ctx);
1624 test_coalesce(ctx);
1625 test_closure(ctx);
1626 test_lexmin(ctx);
1627 isl_ctx_free(ctx);
1628 return 0;