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>
20 void test_read(struct isl_ctx
*ctx
)
22 char filename
[PATH_MAX
];
25 struct isl_basic_set
*bset1
, *bset2
;
26 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
28 n
= snprintf(filename
, sizeof(filename
),
29 "%s/test_inputs/set.omega", srcdir
);
30 assert(n
< sizeof(filename
));
31 input
= fopen(filename
, "r");
34 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
35 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
37 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
39 isl_basic_set_free(bset1
);
40 isl_basic_set_free(bset2
);
45 void test_bounded(struct isl_ctx
*ctx
)
50 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
51 bounded
= isl_set_is_bounded(set
);
55 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
56 bounded
= isl_set_is_bounded(set
);
60 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
61 bounded
= isl_set_is_bounded(set
);
66 /* Construct the basic set { [i] : 5 <= i <= N } */
67 void test_construction(struct isl_ctx
*ctx
)
71 struct isl_basic_set
*bset
;
72 struct isl_constraint
*c
;
76 dim
= isl_dim_set_alloc(ctx
, 1, 1);
77 bset
= isl_basic_set_universe(dim
);
79 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
80 isl_int_set_si(v
, -1);
81 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
83 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
84 bset
= isl_basic_set_add_constraint(bset
, c
);
86 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
88 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
89 isl_int_set_si(v
, -5);
90 isl_constraint_set_constant(c
, v
);
91 bset
= isl_basic_set_add_constraint(bset
, c
);
93 isl_basic_set_free(bset
);
98 void test_dim(struct isl_ctx
*ctx
)
101 isl_map
*map1
, *map2
;
103 map1
= isl_map_read_from_str(ctx
,
104 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
105 map1
= isl_map_add(map1
, isl_dim_in
, 1);
106 map2
= isl_map_read_from_str(ctx
,
107 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
108 assert(isl_map_is_equal(map1
, map2
));
111 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
112 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
113 assert(isl_map_is_equal(map1
, map2
));
118 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
119 map1
= isl_map_read_from_str(ctx
, str
, -1);
120 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
121 map2
= isl_map_read_from_str(ctx
, str
, -1);
122 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
123 assert(isl_map_is_equal(map1
, map2
));
129 void test_div(struct isl_ctx
*ctx
)
135 struct isl_basic_set
*bset
;
136 struct isl_constraint
*c
;
141 dim
= isl_dim_set_alloc(ctx
, 0, 1);
142 bset
= isl_basic_set_universe(dim
);
144 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
145 isl_int_set_si(v
, -1);
146 isl_constraint_set_constant(c
, v
);
147 isl_int_set_si(v
, 1);
148 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
149 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
150 c
= isl_constraint_add_div(c
, div
, &pos
);
151 isl_int_set_si(v
, 3);
152 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
153 bset
= isl_basic_set_add_constraint(bset
, c
);
155 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
156 isl_int_set_si(v
, 1);
157 isl_constraint_set_constant(c
, v
);
158 isl_int_set_si(v
, -1);
159 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
160 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
161 c
= isl_constraint_add_div(c
, div
, &pos
);
162 isl_int_set_si(v
, 3);
163 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
164 bset
= isl_basic_set_add_constraint(bset
, c
);
166 assert(bset
&& bset
->n_div
== 1);
167 isl_basic_set_free(bset
);
170 dim
= isl_dim_set_alloc(ctx
, 0, 1);
171 bset
= isl_basic_set_universe(dim
);
173 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
174 isl_int_set_si(v
, 1);
175 isl_constraint_set_constant(c
, v
);
176 isl_int_set_si(v
, -1);
177 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
178 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
179 c
= isl_constraint_add_div(c
, div
, &pos
);
180 isl_int_set_si(v
, 3);
181 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
182 bset
= isl_basic_set_add_constraint(bset
, c
);
184 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
185 isl_int_set_si(v
, -1);
186 isl_constraint_set_constant(c
, v
);
187 isl_int_set_si(v
, 1);
188 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
189 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
190 c
= isl_constraint_add_div(c
, div
, &pos
);
191 isl_int_set_si(v
, 3);
192 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
193 bset
= isl_basic_set_add_constraint(bset
, c
);
195 assert(bset
&& bset
->n_div
== 1);
196 isl_basic_set_free(bset
);
199 dim
= isl_dim_set_alloc(ctx
, 0, 1);
200 bset
= isl_basic_set_universe(dim
);
202 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
203 isl_int_set_si(v
, 1);
204 isl_constraint_set_constant(c
, v
);
205 isl_int_set_si(v
, -1);
206 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
207 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
208 c
= isl_constraint_add_div(c
, div
, &pos
);
209 isl_int_set_si(v
, 3);
210 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
211 bset
= isl_basic_set_add_constraint(bset
, c
);
213 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
214 isl_int_set_si(v
, -3);
215 isl_constraint_set_constant(c
, v
);
216 isl_int_set_si(v
, 1);
217 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
218 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
219 c
= isl_constraint_add_div(c
, div
, &pos
);
220 isl_int_set_si(v
, 4);
221 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
222 bset
= isl_basic_set_add_constraint(bset
, c
);
224 assert(bset
&& bset
->n_div
== 1);
225 isl_basic_set_free(bset
);
228 dim
= isl_dim_set_alloc(ctx
, 0, 1);
229 bset
= isl_basic_set_universe(dim
);
231 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
232 isl_int_set_si(v
, 2);
233 isl_constraint_set_constant(c
, v
);
234 isl_int_set_si(v
, -1);
235 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
236 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
237 c
= isl_constraint_add_div(c
, div
, &pos
);
238 isl_int_set_si(v
, 3);
239 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
240 bset
= isl_basic_set_add_constraint(bset
, c
);
242 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
243 isl_int_set_si(v
, -1);
244 isl_constraint_set_constant(c
, v
);
245 isl_int_set_si(v
, 1);
246 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
247 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
248 c
= isl_constraint_add_div(c
, div
, &pos
);
249 isl_int_set_si(v
, 6);
250 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
251 bset
= isl_basic_set_add_constraint(bset
, c
);
253 assert(isl_basic_set_is_empty(bset
));
254 isl_basic_set_free(bset
);
257 dim
= isl_dim_set_alloc(ctx
, 0, 2);
258 bset
= isl_basic_set_universe(dim
);
260 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
261 isl_int_set_si(v
, -1);
262 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
263 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
264 c
= isl_constraint_add_div(c
, div
, &pos
);
265 isl_int_set_si(v
, 3);
266 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
267 bset
= isl_basic_set_add_constraint(bset
, c
);
269 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
270 isl_int_set_si(v
, 1);
271 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
272 isl_int_set_si(v
, -3);
273 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
274 bset
= isl_basic_set_add_constraint(bset
, c
);
276 assert(bset
&& bset
->n_div
== 0);
277 isl_basic_set_free(bset
);
280 dim
= isl_dim_set_alloc(ctx
, 0, 2);
281 bset
= isl_basic_set_universe(dim
);
283 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
284 isl_int_set_si(v
, -1);
285 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
286 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
287 c
= isl_constraint_add_div(c
, div
, &pos
);
288 isl_int_set_si(v
, 6);
289 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
290 bset
= isl_basic_set_add_constraint(bset
, c
);
292 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
293 isl_int_set_si(v
, 1);
294 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
295 isl_int_set_si(v
, -3);
296 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
297 bset
= isl_basic_set_add_constraint(bset
, c
);
299 assert(bset
&& bset
->n_div
== 1);
300 isl_basic_set_free(bset
);
303 /* This test is a bit tricky. We set up an equality
305 * Normalization of divs creates _two_ divs
308 * Afterwards e0 is removed again because it has coefficient -1
309 * and we end up with the original equality and div again.
310 * Perhaps we can avoid the introduction of this temporary div.
312 dim
= isl_dim_set_alloc(ctx
, 0, 3);
313 bset
= isl_basic_set_universe(dim
);
315 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
316 isl_int_set_si(v
, -1);
317 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
318 isl_int_set_si(v
, -3);
319 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
320 isl_int_set_si(v
, -3);
321 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
322 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
323 c
= isl_constraint_add_div(c
, div
, &pos
);
324 isl_int_set_si(v
, 6);
325 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
326 bset
= isl_basic_set_add_constraint(bset
, c
);
328 /* Test disabled for now */
330 assert(bset && bset->n_div == 1);
332 isl_basic_set_free(bset
);
335 dim
= isl_dim_set_alloc(ctx
, 0, 4);
336 bset
= isl_basic_set_universe(dim
);
338 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
339 isl_int_set_si(v
, -1);
340 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
341 isl_int_set_si(v
, -3);
342 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
343 isl_int_set_si(v
, -3);
344 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
345 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
346 c
= isl_constraint_add_div(c
, div
, &pos
);
347 isl_int_set_si(v
, 6);
348 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
349 bset
= isl_basic_set_add_constraint(bset
, c
);
351 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
352 isl_int_set_si(v
, -1);
353 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
354 isl_int_set_si(v
, 1);
355 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
356 isl_int_set_si(v
, 1);
357 isl_constraint_set_constant(c
, v
);
358 bset
= isl_basic_set_add_constraint(bset
, c
);
360 /* Test disabled for now */
362 assert(bset && bset->n_div == 1);
364 isl_basic_set_free(bset
);
367 dim
= isl_dim_set_alloc(ctx
, 0, 2);
368 bset
= isl_basic_set_universe(dim
);
370 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
371 isl_int_set_si(v
, 1);
372 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
373 isl_int_set_si(v
, -1);
374 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
375 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
376 c
= isl_constraint_add_div(c
, div
, &pos
);
377 isl_int_set_si(v
, -2);
378 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
379 bset
= isl_basic_set_add_constraint(bset
, c
);
381 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
382 isl_int_set_si(v
, -1);
383 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
384 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
385 c
= isl_constraint_add_div(c
, div
, &pos
);
386 isl_int_set_si(v
, 3);
387 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
388 isl_int_set_si(v
, 2);
389 isl_constraint_set_constant(c
, v
);
390 bset
= isl_basic_set_add_constraint(bset
, c
);
392 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
394 assert(!isl_basic_set_is_empty(bset
));
396 isl_basic_set_free(bset
);
399 dim
= isl_dim_set_alloc(ctx
, 0, 2);
400 bset
= isl_basic_set_universe(dim
);
402 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
403 isl_int_set_si(v
, 1);
404 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
405 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
406 c
= isl_constraint_add_div(c
, div
, &pos
);
407 isl_int_set_si(v
, -2);
408 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
409 bset
= isl_basic_set_add_constraint(bset
, c
);
411 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
413 isl_basic_set_free(bset
);
418 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
420 char filename
[PATH_MAX
];
423 struct isl_basic_set
*bset1
, *bset2
;
424 struct isl_basic_map
*bmap
;
426 n
= snprintf(filename
, sizeof(filename
),
427 "%s/test_inputs/%s.omega", srcdir
, name
);
428 assert(n
< sizeof(filename
));
429 input
= fopen(filename
, "r");
432 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
433 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
435 bset1
= isl_basic_set_apply(bset1
, bmap
);
437 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
439 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
441 isl_basic_set_free(bset1
);
442 isl_basic_set_free(bset2
);
447 void test_application(struct isl_ctx
*ctx
)
449 test_application_case(ctx
, "application");
450 test_application_case(ctx
, "application2");
453 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
455 char filename
[PATH_MAX
];
458 struct isl_basic_set
*bset1
, *bset2
;
460 n
= snprintf(filename
, sizeof(filename
),
461 "%s/test_inputs/%s.polylib", srcdir
, name
);
462 assert(n
< sizeof(filename
));
463 input
= fopen(filename
, "r");
466 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
467 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
469 bset1
= isl_basic_set_affine_hull(bset1
);
471 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
473 isl_basic_set_free(bset1
);
474 isl_basic_set_free(bset2
);
479 void test_affine_hull(struct isl_ctx
*ctx
)
481 test_affine_hull_case(ctx
, "affine2");
482 test_affine_hull_case(ctx
, "affine");
483 test_affine_hull_case(ctx
, "affine3");
486 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
488 char filename
[PATH_MAX
];
491 struct isl_basic_set
*bset1
, *bset2
;
494 n
= snprintf(filename
, sizeof(filename
),
495 "%s/test_inputs/%s.polylib", srcdir
, name
);
496 assert(n
< sizeof(filename
));
497 input
= fopen(filename
, "r");
500 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
501 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
503 set
= isl_basic_set_union(bset1
, bset2
);
504 bset1
= isl_set_convex_hull(set
);
506 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
508 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
510 isl_basic_set_free(bset1
);
511 isl_basic_set_free(bset2
);
516 void test_convex_hull(struct isl_ctx
*ctx
)
518 const char *str1
, *str2
;
519 isl_set
*set1
, *set2
;
521 test_convex_hull_case(ctx
, "convex0");
522 test_convex_hull_case(ctx
, "convex1");
523 test_convex_hull_case(ctx
, "convex2");
524 test_convex_hull_case(ctx
, "convex3");
525 test_convex_hull_case(ctx
, "convex4");
526 test_convex_hull_case(ctx
, "convex5");
527 test_convex_hull_case(ctx
, "convex6");
528 test_convex_hull_case(ctx
, "convex7");
529 test_convex_hull_case(ctx
, "convex8");
530 test_convex_hull_case(ctx
, "convex9");
531 test_convex_hull_case(ctx
, "convex10");
532 test_convex_hull_case(ctx
, "convex11");
533 test_convex_hull_case(ctx
, "convex12");
534 test_convex_hull_case(ctx
, "convex13");
535 test_convex_hull_case(ctx
, "convex14");
536 test_convex_hull_case(ctx
, "convex15");
538 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
539 "(i0 = 1 and i1 = 0 and i2 = 1) or "
540 "(i0 = 0 and i1 = 0 and i2 = 0) }";
541 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
542 set1
= isl_set_read_from_str(ctx
, str1
, -1);
543 set2
= isl_set_read_from_str(ctx
, str2
, -1);
544 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
545 assert(isl_set_is_equal(set1
, set2
));
550 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
552 char filename
[PATH_MAX
];
555 struct isl_basic_set
*bset1
, *bset2
;
557 n
= snprintf(filename
, sizeof(filename
),
558 "%s/test_inputs/%s.polylib", srcdir
, name
);
559 assert(n
< sizeof(filename
));
560 input
= fopen(filename
, "r");
563 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
564 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
566 bset1
= isl_basic_set_gist(bset1
, bset2
);
568 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
570 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
572 isl_basic_set_free(bset1
);
573 isl_basic_set_free(bset2
);
578 void test_gist(struct isl_ctx
*ctx
)
580 test_gist_case(ctx
, "gist1");
583 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
587 set
= isl_set_read_from_str(ctx
, str
, -1);
588 set
= isl_set_coalesce(set
);
589 set2
= isl_set_read_from_str(ctx
, str
, -1);
590 assert(isl_set_is_equal(set
, set2
));
592 assert(set
&& set
->n
== 1);
597 void test_coalesce(struct isl_ctx
*ctx
)
600 struct isl_set
*set
, *set2
;
601 struct isl_map
*map
, *map2
;
603 set
= isl_set_read_from_str(ctx
,
604 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
605 "y >= x & x >= 2 & 5 >= y }", -1);
606 set
= isl_set_coalesce(set
);
607 assert(set
&& set
->n
== 1);
610 set
= isl_set_read_from_str(ctx
,
611 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
612 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
613 set
= isl_set_coalesce(set
);
614 assert(set
&& set
->n
== 1);
617 set
= isl_set_read_from_str(ctx
,
618 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
619 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
620 set
= isl_set_coalesce(set
);
621 assert(set
&& set
->n
== 2);
624 set
= isl_set_read_from_str(ctx
,
625 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
626 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
627 set
= isl_set_coalesce(set
);
628 assert(set
&& set
->n
== 1);
631 set
= isl_set_read_from_str(ctx
,
632 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
633 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
634 set
= isl_set_coalesce(set
);
635 assert(set
&& set
->n
== 2);
638 set
= isl_set_read_from_str(ctx
,
639 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
640 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
641 set
= isl_set_coalesce(set
);
642 assert(set
&& set
->n
== 2);
645 set
= isl_set_read_from_str(ctx
,
646 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
647 "y >= 0 & x = 6 & y <= 6}", -1);
648 set
= isl_set_coalesce(set
);
649 assert(set
&& set
->n
== 1);
652 set
= isl_set_read_from_str(ctx
,
653 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
654 "y >= 0 & x = 7 & y <= 6}", -1);
655 set
= isl_set_coalesce(set
);
656 assert(set
&& set
->n
== 2);
659 set
= isl_set_read_from_str(ctx
,
660 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
661 "y >= 0 & x = 6 & y <= 5}", -1);
662 set
= isl_set_coalesce(set
);
663 assert(set
&& set
->n
== 1);
664 set2
= isl_set_read_from_str(ctx
,
665 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
666 "y >= 0 & x = 6 & y <= 5}", -1);
667 assert(isl_set_is_equal(set
, set2
));
671 set
= isl_set_read_from_str(ctx
,
672 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
673 "y >= 0 & x = 6 & y <= 7}", -1);
674 set
= isl_set_coalesce(set
);
675 assert(set
&& set
->n
== 2);
678 set
= isl_set_read_from_str(ctx
,
679 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
680 set
= isl_set_coalesce(set
);
681 assert(set
&& set
->n
== 1);
682 set2
= isl_set_read_from_str(ctx
,
683 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
684 assert(isl_set_is_equal(set
, set2
));
688 set
= isl_set_read_from_str(ctx
,
689 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
690 set
= isl_set_coalesce(set
);
691 set2
= isl_set_read_from_str(ctx
,
692 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
693 assert(isl_set_is_equal(set
, set2
));
697 set
= isl_set_read_from_str(ctx
,
698 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
699 "2 <= i and i <= n }", -1);
700 set
= isl_set_coalesce(set
);
701 assert(set
&& set
->n
== 1);
702 set2
= isl_set_read_from_str(ctx
,
703 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
704 "2 <= i and i <= n }", -1);
705 assert(isl_set_is_equal(set
, set2
));
709 map
= isl_map_read_from_str(ctx
,
710 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
711 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
712 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
713 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
714 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
715 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
716 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
717 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
718 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
719 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
720 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
721 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
722 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
723 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
724 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
725 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
726 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
727 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
728 map
= isl_map_coalesce(map
);
729 map2
= isl_map_read_from_str(ctx
,
730 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
731 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
732 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
733 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
734 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
735 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
736 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
737 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
738 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
739 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
740 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
741 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
742 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
743 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
744 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
745 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
746 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
747 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
748 assert(isl_map_is_equal(map
, map2
));
752 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
753 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
754 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
755 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
756 map
= isl_map_read_from_str(ctx
, str
, -1);
757 map
= isl_map_coalesce(map
);
758 map2
= isl_map_read_from_str(ctx
, str
, -1);
759 assert(isl_map_is_equal(map
, map2
));
763 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
764 "[o0, o1, o2, o3, o4, o5, o6] : "
765 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
766 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
767 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
768 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
769 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
770 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
771 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
772 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
773 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
774 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
775 "o6 >= i3 + i6 - o3 and M >= 0 and "
776 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
777 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
778 map
= isl_map_read_from_str(ctx
, str
, -1);
779 map
= isl_map_coalesce(map
);
780 map2
= isl_map_read_from_str(ctx
, str
, -1);
781 assert(isl_map_is_equal(map
, map2
));
785 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
786 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
787 "(o0 = 0 and M >= 2 and N >= 3) or "
788 "(M = 0 and o0 = 0 and N >= 3) }";
789 map
= isl_map_read_from_str(ctx
, str
, -1);
790 map
= isl_map_coalesce(map
);
791 map2
= isl_map_read_from_str(ctx
, str
, -1);
792 assert(isl_map_is_equal(map
, map2
));
796 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
797 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
798 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
799 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
800 map
= isl_map_read_from_str(ctx
, str
, -1);
801 map
= isl_map_coalesce(map
);
802 map2
= isl_map_read_from_str(ctx
, str
, -1);
803 assert(isl_map_is_equal(map
, map2
));
807 test_coalesce_set(ctx
,
808 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
809 "(i1 = M and M >= 1) }", 0);
810 test_coalesce_set(ctx
,
811 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
812 test_coalesce_set(ctx
,
813 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
814 "(y = 3 and x = 1) }", 1);
815 test_coalesce_set(ctx
,
816 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
817 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
818 "i1 <= M and i3 <= M and i4 <= M) or "
819 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
820 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
821 "i4 <= -1 + M) }", 1);
822 test_coalesce_set(ctx
,
823 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
824 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
825 test_coalesce_set(ctx
,
826 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
827 "-x - y + 1 >= 0 and -3 <= z <= 3;"
828 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
829 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
830 test_coalesce_set(ctx
,
831 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
834 void test_closure(struct isl_ctx
*ctx
)
842 /* COCOA example 1 */
843 map
= isl_map_read_from_str(ctx
,
844 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
845 "1 <= i and i < n and 1 <= j and j < n or "
846 "i2 = i + 1 and j2 = j - 1 and "
847 "1 <= i and i < n and 2 <= j and j <= n }", -1);
848 map
= isl_map_power(map
, 1, &exact
);
852 /* COCOA example 1 */
853 map
= isl_map_read_from_str(ctx
,
854 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
855 "1 <= i and i < n and 1 <= j and j < n or "
856 "i2 = i + 1 and j2 = j - 1 and "
857 "1 <= i and i < n and 2 <= j and j <= n }", -1);
858 map
= isl_map_transitive_closure(map
, &exact
);
860 map2
= isl_map_read_from_str(ctx
,
861 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
862 "1 <= i and i < n and 1 <= j and j <= n and "
863 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
864 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
865 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
866 assert(isl_map_is_equal(map
, map2
));
870 map
= isl_map_read_from_str(ctx
,
871 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
872 " 0 <= y and y <= n }", -1);
873 map
= isl_map_transitive_closure(map
, &exact
);
874 map2
= isl_map_read_from_str(ctx
,
875 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
876 " 0 <= y and y <= n }", -1);
877 assert(isl_map_is_equal(map
, map2
));
881 /* COCOA example 2 */
882 map
= isl_map_read_from_str(ctx
,
883 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
884 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
885 "i2 = i + 2 and j2 = j - 2 and "
886 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
887 map
= isl_map_transitive_closure(map
, &exact
);
889 map2
= isl_map_read_from_str(ctx
,
890 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
891 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
892 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
893 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
894 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
895 assert(isl_map_is_equal(map
, map2
));
899 /* COCOA Fig.2 left */
900 map
= isl_map_read_from_str(ctx
,
901 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
902 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
904 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
905 "j <= 2 i - 3 and j <= n - 2 or "
906 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
907 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
908 map
= isl_map_transitive_closure(map
, &exact
);
912 /* COCOA Fig.2 right */
913 map
= isl_map_read_from_str(ctx
,
914 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
915 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
917 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
918 "j <= 2 i - 4 and j <= n - 3 or "
919 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
920 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
921 map
= isl_map_power(map
, 1, &exact
);
925 /* COCOA Fig.2 right */
926 map
= isl_map_read_from_str(ctx
,
927 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
928 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
930 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
931 "j <= 2 i - 4 and j <= n - 3 or "
932 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
933 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
934 map
= isl_map_transitive_closure(map
, &exact
);
936 map2
= isl_map_read_from_str(ctx
,
937 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
938 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
939 "j <= n and 3 + i + 2 j <= 3 n and "
940 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
941 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
942 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
943 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
944 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
945 assert(isl_map_is_equal(map
, map2
));
949 /* COCOA Fig.1 right */
950 dom
= isl_set_read_from_str(ctx
,
951 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
952 "2 x - 3 y + 3 >= 0 }", -1);
953 right
= isl_map_read_from_str(ctx
,
954 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
955 up
= isl_map_read_from_str(ctx
,
956 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
957 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
958 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
959 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
960 up
= isl_map_intersect_range(up
, dom
);
961 map
= isl_map_union(up
, right
);
962 map
= isl_map_transitive_closure(map
, &exact
);
964 map2
= isl_map_read_from_str(ctx
,
965 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
966 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
967 assert(isl_map_is_equal(map
, map2
));
971 /* COCOA Theorem 1 counter example */
972 map
= isl_map_read_from_str(ctx
,
973 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
974 "i2 = 1 and j2 = j or "
975 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
976 map
= isl_map_transitive_closure(map
, &exact
);
980 map
= isl_map_read_from_str(ctx
,
981 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
982 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
983 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
984 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
985 map
= isl_map_transitive_closure(map
, &exact
);
989 /* Kelly et al 1996, fig 12 */
990 map
= isl_map_read_from_str(ctx
,
991 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
992 "1 <= i,j,j+1 <= n or "
993 "j = n and j2 = 1 and i2 = i + 1 and "
994 "1 <= i,i+1 <= n }", -1);
995 map
= isl_map_transitive_closure(map
, &exact
);
997 map2
= isl_map_read_from_str(ctx
,
998 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
999 "1 <= i <= n and i = i2 or "
1000 "1 <= i < i2 <= n and 1 <= j <= n and "
1001 "1 <= j2 <= n }", -1);
1002 assert(isl_map_is_equal(map
, map2
));
1006 /* Omega's closure4 */
1007 map
= isl_map_read_from_str(ctx
,
1008 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1009 "1 <= x,y <= 10 or "
1010 "x2 = x + 1 and y2 = y and "
1011 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1012 map
= isl_map_transitive_closure(map
, &exact
);
1016 map
= isl_map_read_from_str(ctx
,
1017 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1018 map
= isl_map_transitive_closure(map
, &exact
);
1020 map2
= isl_map_read_from_str(ctx
,
1021 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1022 assert(isl_map_is_equal(map
, map2
));
1026 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1027 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1028 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1029 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1030 map
= isl_map_read_from_str(ctx
, str
, -1);
1031 map
= isl_map_transitive_closure(map
, &exact
);
1033 map2
= isl_map_read_from_str(ctx
, str
, -1);
1034 assert(isl_map_is_equal(map
, map2
));
1038 str
= "{[0] -> [1]; [2] -> [3]}";
1039 map
= isl_map_read_from_str(ctx
, str
, -1);
1040 map
= isl_map_transitive_closure(map
, &exact
);
1042 map2
= isl_map_read_from_str(ctx
, str
, -1);
1043 assert(isl_map_is_equal(map
, map2
));
1048 void test_lex(struct isl_ctx
*ctx
)
1053 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1054 map
= isl_map_lex_le(dim
);
1055 assert(!isl_map_is_empty(map
));
1059 void test_lexmin(struct isl_ctx
*ctx
)
1066 str
= "[p0, p1] -> { [] -> [] : "
1067 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1068 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1069 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1070 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1071 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1072 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1073 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1074 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1075 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1076 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1077 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1078 map
= isl_map_read_from_str(ctx
, str
, -1);
1079 map
= isl_map_lexmin(map
);
1082 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1083 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1084 set
= isl_set_read_from_str(ctx
, str
, -1);
1085 set
= isl_set_lexmax(set
);
1086 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1087 set2
= isl_set_read_from_str(ctx
, str
, -1);
1088 set
= isl_set_intersect(set
, set2
);
1089 assert(!isl_set_is_empty(set
));
1098 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1099 void *dep_user
, void *user
)
1101 struct must_may
*mm
= (struct must_may
*)user
;
1104 mm
->must
= isl_map_union(mm
->must
, dep
);
1106 mm
->may
= isl_map_union(mm
->may
, dep
);
1111 static int common_space(void *first
, void *second
)
1113 int depth
= *(int *)first
;
1117 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1125 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1126 equal
= isl_map_is_equal(map
, map2
);
1132 void test_dep(struct isl_ctx
*ctx
)
1137 isl_access_info
*ai
;
1144 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1145 map
= isl_map_read_from_str(ctx
, str
, -1);
1146 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1148 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1149 map
= isl_map_read_from_str(ctx
, str
, -1);
1150 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1152 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1153 map
= isl_map_read_from_str(ctx
, str
, -1);
1154 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1156 flow
= isl_access_info_compute_flow(ai
);
1157 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1158 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1159 mm
.may
= isl_map_empty(dim
);
1161 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1163 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1164 " [1,10,0] -> [2,5,0] }";
1165 assert(map_is_equal(mm
.must
, str
));
1166 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1167 assert(map_is_equal(mm
.may
, str
));
1169 isl_map_free(mm
.must
);
1170 isl_map_free(mm
.may
);
1171 isl_flow_free(flow
);
1174 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1175 map
= isl_map_read_from_str(ctx
, str
, -1);
1176 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1178 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1179 map
= isl_map_read_from_str(ctx
, str
, -1);
1180 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1182 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1183 map
= isl_map_read_from_str(ctx
, str
, -1);
1184 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1186 flow
= isl_access_info_compute_flow(ai
);
1187 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1188 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1189 mm
.may
= isl_map_empty(dim
);
1191 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1193 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1194 assert(map_is_equal(mm
.must
, str
));
1195 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1196 assert(map_is_equal(mm
.may
, str
));
1198 isl_map_free(mm
.must
);
1199 isl_map_free(mm
.may
);
1200 isl_flow_free(flow
);
1203 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1204 map
= isl_map_read_from_str(ctx
, str
, -1);
1205 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1207 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1208 map
= isl_map_read_from_str(ctx
, str
, -1);
1209 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1211 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1212 map
= isl_map_read_from_str(ctx
, str
, -1);
1213 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1215 flow
= isl_access_info_compute_flow(ai
);
1216 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1217 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1218 mm
.may
= isl_map_empty(dim
);
1220 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1222 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1223 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1224 assert(map_is_equal(mm
.may
, str
));
1225 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1226 assert(map_is_equal(mm
.must
, str
));
1228 isl_map_free(mm
.must
);
1229 isl_map_free(mm
.may
);
1230 isl_flow_free(flow
);
1233 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1234 map
= isl_map_read_from_str(ctx
, str
, -1);
1235 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1237 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1238 map
= isl_map_read_from_str(ctx
, str
, -1);
1239 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1241 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1242 map
= isl_map_read_from_str(ctx
, str
, -1);
1243 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1245 flow
= isl_access_info_compute_flow(ai
);
1246 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1247 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1248 mm
.may
= isl_map_empty(dim
);
1250 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1252 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1253 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1254 assert(map_is_equal(mm
.may
, str
));
1255 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1256 assert(map_is_equal(mm
.must
, str
));
1258 isl_map_free(mm
.must
);
1259 isl_map_free(mm
.may
);
1260 isl_flow_free(flow
);
1263 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1264 map
= isl_map_read_from_str(ctx
, str
, -1);
1265 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1267 str
= "{ [0,i,0] -> [i] : 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 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1272 map
= isl_map_read_from_str(ctx
, str
, -1);
1273 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1275 flow
= isl_access_info_compute_flow(ai
);
1276 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1277 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1278 mm
.may
= isl_map_empty(dim
);
1280 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1282 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1283 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1284 assert(map_is_equal(mm
.may
, str
));
1285 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1286 assert(map_is_equal(mm
.must
, str
));
1288 isl_map_free(mm
.must
);
1289 isl_map_free(mm
.may
);
1290 isl_flow_free(flow
);
1295 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1296 map
= isl_map_read_from_str(ctx
, str
, -1);
1297 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1299 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1300 map
= isl_map_read_from_str(ctx
, str
, -1);
1301 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1303 flow
= isl_access_info_compute_flow(ai
);
1304 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1305 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1306 mm
.may
= isl_map_empty(dim
);
1308 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1310 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1311 assert(map_is_equal(mm
.must
, str
));
1312 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1313 assert(map_is_equal(mm
.may
, str
));
1315 isl_map_free(mm
.must
);
1316 isl_map_free(mm
.may
);
1317 isl_flow_free(flow
);
1320 void test_sv(struct isl_ctx
*ctx
)
1325 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1326 map
= isl_map_read_from_str(ctx
, str
, -1);
1327 assert(isl_map_is_single_valued(map
));
1330 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1331 map
= isl_map_read_from_str(ctx
, str
, -1);
1332 assert(!isl_map_is_single_valued(map
));
1336 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1340 map
= isl_map_read_from_str(ctx
, str
, -1);
1342 assert(isl_map_is_bijective(map
));
1344 assert(!isl_map_is_bijective(map
));
1348 void test_bijective(struct isl_ctx
*ctx
)
1350 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1351 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1352 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1353 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1354 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1355 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1356 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1357 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1358 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1359 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1360 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1361 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1362 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1367 struct isl_ctx
*ctx
;
1369 srcdir
= getenv("srcdir");
1372 ctx
= isl_ctx_alloc();
1375 test_bijective(ctx
);
1379 test_construction(ctx
);
1382 test_application(ctx
);
1383 test_affine_hull(ctx
);
1384 test_convex_hull(ctx
);