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