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>
18 #include <isl_union_map.h>
22 void test_parse_map(isl_ctx
*ctx
, const char *str
)
26 map
= isl_map_read_from_str(ctx
, str
, -1);
31 void test_parse(struct isl_ctx
*ctx
)
36 str
= "{ [i] -> [-i] }";
37 map
= isl_map_read_from_str(ctx
, str
, -1);
41 str
= "{ A[i] -> L[([i/3])] }";
42 map
= isl_map_read_from_str(ctx
, str
, -1);
46 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
49 void test_read(struct isl_ctx
*ctx
)
51 char filename
[PATH_MAX
];
54 struct isl_basic_set
*bset1
, *bset2
;
55 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
57 n
= snprintf(filename
, sizeof(filename
),
58 "%s/test_inputs/set.omega", srcdir
);
59 assert(n
< sizeof(filename
));
60 input
= fopen(filename
, "r");
63 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
64 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
66 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
68 isl_basic_set_free(bset1
);
69 isl_basic_set_free(bset2
);
74 void test_bounded(struct isl_ctx
*ctx
)
79 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
80 bounded
= isl_set_is_bounded(set
);
84 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
85 bounded
= isl_set_is_bounded(set
);
89 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
90 bounded
= isl_set_is_bounded(set
);
95 /* Construct the basic set { [i] : 5 <= i <= N } */
96 void test_construction(struct isl_ctx
*ctx
)
100 struct isl_basic_set
*bset
;
101 struct isl_constraint
*c
;
105 dim
= isl_dim_set_alloc(ctx
, 1, 1);
106 bset
= isl_basic_set_universe(dim
);
108 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
109 isl_int_set_si(v
, -1);
110 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
111 isl_int_set_si(v
, 1);
112 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
113 bset
= isl_basic_set_add_constraint(bset
, c
);
115 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
116 isl_int_set_si(v
, 1);
117 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
118 isl_int_set_si(v
, -5);
119 isl_constraint_set_constant(c
, v
);
120 bset
= isl_basic_set_add_constraint(bset
, c
);
122 isl_basic_set_free(bset
);
127 void test_dim(struct isl_ctx
*ctx
)
130 isl_map
*map1
, *map2
;
132 map1
= isl_map_read_from_str(ctx
,
133 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
134 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
135 map2
= isl_map_read_from_str(ctx
,
136 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
137 assert(isl_map_is_equal(map1
, map2
));
140 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
141 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
142 assert(isl_map_is_equal(map1
, map2
));
147 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
148 map1
= isl_map_read_from_str(ctx
, str
, -1);
149 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
150 map2
= isl_map_read_from_str(ctx
, str
, -1);
151 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
152 assert(isl_map_is_equal(map1
, map2
));
158 void test_div(struct isl_ctx
*ctx
)
164 struct isl_basic_set
*bset
;
165 struct isl_constraint
*c
;
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
, -1);
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
, 3);
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
, 1);
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
, -3);
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
, 4);
250 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
251 bset
= isl_basic_set_add_constraint(bset
, c
);
253 assert(bset
&& bset
->n_div
== 1);
254 isl_basic_set_free(bset
);
257 dim
= isl_dim_set_alloc(ctx
, 0, 1);
258 bset
= isl_basic_set_universe(dim
);
260 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
261 isl_int_set_si(v
, 2);
262 isl_constraint_set_constant(c
, v
);
263 isl_int_set_si(v
, -1);
264 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
265 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
266 c
= isl_constraint_add_div(c
, div
, &pos
);
267 isl_int_set_si(v
, 3);
268 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
269 bset
= isl_basic_set_add_constraint(bset
, c
);
271 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
272 isl_int_set_si(v
, -1);
273 isl_constraint_set_constant(c
, v
);
274 isl_int_set_si(v
, 1);
275 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
276 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
277 c
= isl_constraint_add_div(c
, div
, &pos
);
278 isl_int_set_si(v
, 6);
279 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
280 bset
= isl_basic_set_add_constraint(bset
, c
);
282 assert(isl_basic_set_is_empty(bset
));
283 isl_basic_set_free(bset
);
286 dim
= isl_dim_set_alloc(ctx
, 0, 2);
287 bset
= isl_basic_set_universe(dim
);
289 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
290 isl_int_set_si(v
, -1);
291 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
292 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
293 c
= isl_constraint_add_div(c
, div
, &pos
);
294 isl_int_set_si(v
, 3);
295 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
296 bset
= isl_basic_set_add_constraint(bset
, c
);
298 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
299 isl_int_set_si(v
, 1);
300 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
301 isl_int_set_si(v
, -3);
302 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
303 bset
= isl_basic_set_add_constraint(bset
, c
);
305 assert(bset
&& bset
->n_div
== 0);
306 isl_basic_set_free(bset
);
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
, 6);
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
== 1);
329 isl_basic_set_free(bset
);
332 /* This test is a bit tricky. We set up an equality
334 * Normalization of divs creates _two_ divs
337 * Afterwards e0 is removed again because it has coefficient -1
338 * and we end up with the original equality and div again.
339 * Perhaps we can avoid the introduction of this temporary div.
341 dim
= isl_dim_set_alloc(ctx
, 0, 3);
342 bset
= isl_basic_set_universe(dim
);
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 isl_int_set_si(v
, -3);
350 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
351 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
352 c
= isl_constraint_add_div(c
, div
, &pos
);
353 isl_int_set_si(v
, 6);
354 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
355 bset
= isl_basic_set_add_constraint(bset
, c
);
357 /* Test disabled for now */
359 assert(bset && bset->n_div == 1);
361 isl_basic_set_free(bset
);
364 dim
= isl_dim_set_alloc(ctx
, 0, 4);
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
, 3, 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 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
381 isl_int_set_si(v
, -1);
382 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
383 isl_int_set_si(v
, 1);
384 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
385 isl_int_set_si(v
, 1);
386 isl_constraint_set_constant(c
, v
);
387 bset
= isl_basic_set_add_constraint(bset
, c
);
389 /* Test disabled for now */
391 assert(bset && bset->n_div == 1);
393 isl_basic_set_free(bset
);
396 dim
= isl_dim_set_alloc(ctx
, 0, 2);
397 bset
= isl_basic_set_universe(dim
);
399 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
400 isl_int_set_si(v
, 1);
401 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
402 isl_int_set_si(v
, -1);
403 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
404 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
405 c
= isl_constraint_add_div(c
, div
, &pos
);
406 isl_int_set_si(v
, -2);
407 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
408 bset
= isl_basic_set_add_constraint(bset
, c
);
410 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
411 isl_int_set_si(v
, -1);
412 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
413 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
414 c
= isl_constraint_add_div(c
, div
, &pos
);
415 isl_int_set_si(v
, 3);
416 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
417 isl_int_set_si(v
, 2);
418 isl_constraint_set_constant(c
, v
);
419 bset
= isl_basic_set_add_constraint(bset
, c
);
421 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
423 assert(!isl_basic_set_is_empty(bset
));
425 isl_basic_set_free(bset
);
428 dim
= isl_dim_set_alloc(ctx
, 0, 2);
429 bset
= isl_basic_set_universe(dim
);
431 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
432 isl_int_set_si(v
, 1);
433 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
434 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
435 c
= isl_constraint_add_div(c
, div
, &pos
);
436 isl_int_set_si(v
, -2);
437 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
438 bset
= isl_basic_set_add_constraint(bset
, c
);
440 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
442 isl_basic_set_free(bset
);
447 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
449 char filename
[PATH_MAX
];
452 struct isl_basic_set
*bset1
, *bset2
;
453 struct isl_basic_map
*bmap
;
455 n
= snprintf(filename
, sizeof(filename
),
456 "%s/test_inputs/%s.omega", srcdir
, name
);
457 assert(n
< sizeof(filename
));
458 input
= fopen(filename
, "r");
461 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
462 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
464 bset1
= isl_basic_set_apply(bset1
, bmap
);
466 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
468 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
470 isl_basic_set_free(bset1
);
471 isl_basic_set_free(bset2
);
476 void test_application(struct isl_ctx
*ctx
)
478 test_application_case(ctx
, "application");
479 test_application_case(ctx
, "application2");
482 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
484 char filename
[PATH_MAX
];
487 struct isl_basic_set
*bset1
, *bset2
;
489 n
= snprintf(filename
, sizeof(filename
),
490 "%s/test_inputs/%s.polylib", srcdir
, name
);
491 assert(n
< sizeof(filename
));
492 input
= fopen(filename
, "r");
495 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
496 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
498 bset1
= isl_basic_set_affine_hull(bset1
);
500 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
502 isl_basic_set_free(bset1
);
503 isl_basic_set_free(bset2
);
508 void test_affine_hull(struct isl_ctx
*ctx
)
510 test_affine_hull_case(ctx
, "affine2");
511 test_affine_hull_case(ctx
, "affine");
512 test_affine_hull_case(ctx
, "affine3");
515 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
517 char filename
[PATH_MAX
];
520 struct isl_basic_set
*bset1
, *bset2
;
523 n
= snprintf(filename
, sizeof(filename
),
524 "%s/test_inputs/%s.polylib", srcdir
, name
);
525 assert(n
< sizeof(filename
));
526 input
= fopen(filename
, "r");
529 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
530 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
532 set
= isl_basic_set_union(bset1
, bset2
);
533 bset1
= isl_set_convex_hull(set
);
535 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
537 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
539 isl_basic_set_free(bset1
);
540 isl_basic_set_free(bset2
);
545 void test_convex_hull(struct isl_ctx
*ctx
)
547 const char *str1
, *str2
;
548 isl_set
*set1
, *set2
;
550 test_convex_hull_case(ctx
, "convex0");
551 test_convex_hull_case(ctx
, "convex1");
552 test_convex_hull_case(ctx
, "convex2");
553 test_convex_hull_case(ctx
, "convex3");
554 test_convex_hull_case(ctx
, "convex4");
555 test_convex_hull_case(ctx
, "convex5");
556 test_convex_hull_case(ctx
, "convex6");
557 test_convex_hull_case(ctx
, "convex7");
558 test_convex_hull_case(ctx
, "convex8");
559 test_convex_hull_case(ctx
, "convex9");
560 test_convex_hull_case(ctx
, "convex10");
561 test_convex_hull_case(ctx
, "convex11");
562 test_convex_hull_case(ctx
, "convex12");
563 test_convex_hull_case(ctx
, "convex13");
564 test_convex_hull_case(ctx
, "convex14");
565 test_convex_hull_case(ctx
, "convex15");
567 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
568 "(i0 = 1 and i1 = 0 and i2 = 1) or "
569 "(i0 = 0 and i1 = 0 and i2 = 0) }";
570 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
571 set1
= isl_set_read_from_str(ctx
, str1
, -1);
572 set2
= isl_set_read_from_str(ctx
, str2
, -1);
573 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
574 assert(isl_set_is_equal(set1
, set2
));
579 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
581 char filename
[PATH_MAX
];
584 struct isl_basic_set
*bset1
, *bset2
;
586 n
= snprintf(filename
, sizeof(filename
),
587 "%s/test_inputs/%s.polylib", srcdir
, name
);
588 assert(n
< sizeof(filename
));
589 input
= fopen(filename
, "r");
592 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
593 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
595 bset1
= isl_basic_set_gist(bset1
, bset2
);
597 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
599 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
601 isl_basic_set_free(bset1
);
602 isl_basic_set_free(bset2
);
607 void test_gist(struct isl_ctx
*ctx
)
609 test_gist_case(ctx
, "gist1");
612 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
616 set
= isl_set_read_from_str(ctx
, str
, -1);
617 set
= isl_set_coalesce(set
);
618 set2
= isl_set_read_from_str(ctx
, str
, -1);
619 assert(isl_set_is_equal(set
, set2
));
621 assert(set
&& set
->n
== 1);
626 void test_coalesce(struct isl_ctx
*ctx
)
629 struct isl_set
*set
, *set2
;
630 struct isl_map
*map
, *map2
;
632 set
= isl_set_read_from_str(ctx
,
633 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
634 "y >= x & x >= 2 & 5 >= y }", -1);
635 set
= isl_set_coalesce(set
);
636 assert(set
&& set
->n
== 1);
639 set
= isl_set_read_from_str(ctx
,
640 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
641 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
642 set
= isl_set_coalesce(set
);
643 assert(set
&& set
->n
== 1);
646 set
= isl_set_read_from_str(ctx
,
647 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
648 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
649 set
= isl_set_coalesce(set
);
650 assert(set
&& set
->n
== 2);
653 set
= isl_set_read_from_str(ctx
,
654 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
655 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
656 set
= isl_set_coalesce(set
);
657 assert(set
&& set
->n
== 1);
660 set
= isl_set_read_from_str(ctx
,
661 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
662 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
663 set
= isl_set_coalesce(set
);
664 assert(set
&& set
->n
== 2);
667 set
= isl_set_read_from_str(ctx
,
668 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
669 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
670 set
= isl_set_coalesce(set
);
671 assert(set
&& set
->n
== 2);
674 set
= isl_set_read_from_str(ctx
,
675 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
676 "y >= 0 & x = 6 & y <= 6}", -1);
677 set
= isl_set_coalesce(set
);
678 assert(set
&& set
->n
== 1);
681 set
= isl_set_read_from_str(ctx
,
682 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
683 "y >= 0 & x = 7 & y <= 6}", -1);
684 set
= isl_set_coalesce(set
);
685 assert(set
&& set
->n
== 2);
688 set
= isl_set_read_from_str(ctx
,
689 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
690 "y >= 0 & x = 6 & y <= 5}", -1);
691 set
= isl_set_coalesce(set
);
692 assert(set
&& set
->n
== 1);
693 set2
= isl_set_read_from_str(ctx
,
694 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
695 "y >= 0 & x = 6 & y <= 5}", -1);
696 assert(isl_set_is_equal(set
, set2
));
700 set
= isl_set_read_from_str(ctx
,
701 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
702 "y >= 0 & x = 6 & y <= 7}", -1);
703 set
= isl_set_coalesce(set
);
704 assert(set
&& set
->n
== 2);
707 set
= isl_set_read_from_str(ctx
,
708 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
709 set
= isl_set_coalesce(set
);
710 assert(set
&& set
->n
== 1);
711 set2
= isl_set_read_from_str(ctx
,
712 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
713 assert(isl_set_is_equal(set
, set2
));
717 set
= isl_set_read_from_str(ctx
,
718 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
719 set
= isl_set_coalesce(set
);
720 set2
= isl_set_read_from_str(ctx
,
721 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
722 assert(isl_set_is_equal(set
, set2
));
726 set
= isl_set_read_from_str(ctx
,
727 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
728 "2 <= i and i <= n }", -1);
729 set
= isl_set_coalesce(set
);
730 assert(set
&& set
->n
== 1);
731 set2
= isl_set_read_from_str(ctx
,
732 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
733 "2 <= i and i <= n }", -1);
734 assert(isl_set_is_equal(set
, set2
));
738 map
= isl_map_read_from_str(ctx
,
739 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
740 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
741 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
742 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
743 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
744 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
745 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
746 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
747 "[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 2e0 >= 3 + n and e0 <= -4 + n and "
751 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
752 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
753 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
754 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
755 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
756 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
757 map
= isl_map_coalesce(map
);
758 map2
= isl_map_read_from_str(ctx
,
759 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
760 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
761 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
762 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
763 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
764 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
765 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
766 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
767 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
768 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
769 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
770 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
771 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
772 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
773 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
774 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
775 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
776 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
777 assert(isl_map_is_equal(map
, map2
));
781 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
782 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
783 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
784 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
785 map
= isl_map_read_from_str(ctx
, str
, -1);
786 map
= isl_map_coalesce(map
);
787 map2
= isl_map_read_from_str(ctx
, str
, -1);
788 assert(isl_map_is_equal(map
, map2
));
792 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
793 "[o0, o1, o2, o3, o4, o5, o6] : "
794 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
795 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
796 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
797 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
798 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
799 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
800 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
801 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
802 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
803 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
804 "o6 >= i3 + i6 - o3 and M >= 0 and "
805 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
806 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
807 map
= isl_map_read_from_str(ctx
, str
, -1);
808 map
= isl_map_coalesce(map
);
809 map2
= isl_map_read_from_str(ctx
, str
, -1);
810 assert(isl_map_is_equal(map
, map2
));
814 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
815 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
816 "(o0 = 0 and M >= 2 and N >= 3) or "
817 "(M = 0 and o0 = 0 and N >= 3) }";
818 map
= isl_map_read_from_str(ctx
, str
, -1);
819 map
= isl_map_coalesce(map
);
820 map2
= isl_map_read_from_str(ctx
, str
, -1);
821 assert(isl_map_is_equal(map
, map2
));
825 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
826 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
827 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
828 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
829 map
= isl_map_read_from_str(ctx
, str
, -1);
830 map
= isl_map_coalesce(map
);
831 map2
= isl_map_read_from_str(ctx
, str
, -1);
832 assert(isl_map_is_equal(map
, map2
));
836 test_coalesce_set(ctx
,
837 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
838 "(i1 = M and M >= 1) }", 0);
839 test_coalesce_set(ctx
,
840 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
841 test_coalesce_set(ctx
,
842 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
843 "(y = 3 and x = 1) }", 1);
844 test_coalesce_set(ctx
,
845 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
846 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
847 "i1 <= M and i3 <= M and i4 <= M) or "
848 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
849 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
850 "i4 <= -1 + M) }", 1);
851 test_coalesce_set(ctx
,
852 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
853 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
854 test_coalesce_set(ctx
,
855 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
856 "-x - y + 1 >= 0 and -3 <= z <= 3;"
857 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
858 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
859 test_coalesce_set(ctx
,
860 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
861 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
862 test_coalesce_set(ctx
,
863 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
864 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
867 void test_closure(struct isl_ctx
*ctx
)
875 /* COCOA example 1 */
876 map
= isl_map_read_from_str(ctx
,
877 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
878 "1 <= i and i < n and 1 <= j and j < n or "
879 "i2 = i + 1 and j2 = j - 1 and "
880 "1 <= i and i < n and 2 <= j and j <= n }", -1);
881 map
= isl_map_power(map
, 1, &exact
);
885 /* COCOA example 1 */
886 map
= isl_map_read_from_str(ctx
,
887 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
888 "1 <= i and i < n and 1 <= j and j < n or "
889 "i2 = i + 1 and j2 = j - 1 and "
890 "1 <= i and i < n and 2 <= j and j <= n }", -1);
891 map
= isl_map_transitive_closure(map
, &exact
);
893 map2
= isl_map_read_from_str(ctx
,
894 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
895 "1 <= i and i < n and 1 <= j and j <= n and "
896 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
897 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
898 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
899 assert(isl_map_is_equal(map
, map2
));
903 map
= isl_map_read_from_str(ctx
,
904 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
905 " 0 <= y and y <= n }", -1);
906 map
= isl_map_transitive_closure(map
, &exact
);
907 map2
= isl_map_read_from_str(ctx
,
908 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
909 " 0 <= y and y <= n }", -1);
910 assert(isl_map_is_equal(map
, map2
));
914 /* COCOA example 2 */
915 map
= isl_map_read_from_str(ctx
,
916 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
917 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
918 "i2 = i + 2 and j2 = j - 2 and "
919 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
920 map
= isl_map_transitive_closure(map
, &exact
);
922 map2
= isl_map_read_from_str(ctx
,
923 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
924 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
925 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
926 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
927 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
928 assert(isl_map_is_equal(map
, map2
));
932 /* COCOA Fig.2 left */
933 map
= isl_map_read_from_str(ctx
,
934 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
935 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
937 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
938 "j <= 2 i - 3 and j <= n - 2 or "
939 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
940 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
941 map
= isl_map_transitive_closure(map
, &exact
);
945 /* COCOA Fig.2 right */
946 map
= isl_map_read_from_str(ctx
,
947 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
948 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
950 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
951 "j <= 2 i - 4 and j <= n - 3 or "
952 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
953 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
954 map
= isl_map_power(map
, 1, &exact
);
958 /* COCOA Fig.2 right */
959 map
= isl_map_read_from_str(ctx
,
960 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
961 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
963 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
964 "j <= 2 i - 4 and j <= n - 3 or "
965 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
966 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
967 map
= isl_map_transitive_closure(map
, &exact
);
969 map2
= isl_map_read_from_str(ctx
,
970 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
971 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
972 "j <= n and 3 + i + 2 j <= 3 n and "
973 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
974 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
975 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
976 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
977 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
978 assert(isl_map_is_equal(map
, map2
));
982 /* COCOA Fig.1 right */
983 dom
= isl_set_read_from_str(ctx
,
984 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
985 "2 x - 3 y + 3 >= 0 }", -1);
986 right
= isl_map_read_from_str(ctx
,
987 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
988 up
= isl_map_read_from_str(ctx
,
989 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
990 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
991 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
992 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
993 up
= isl_map_intersect_range(up
, dom
);
994 map
= isl_map_union(up
, right
);
995 map
= isl_map_transitive_closure(map
, &exact
);
997 map2
= isl_map_read_from_str(ctx
,
998 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
999 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1000 assert(isl_map_is_equal(map
, map2
));
1004 /* COCOA Theorem 1 counter example */
1005 map
= isl_map_read_from_str(ctx
,
1006 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1007 "i2 = 1 and j2 = j or "
1008 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1009 map
= isl_map_transitive_closure(map
, &exact
);
1013 map
= isl_map_read_from_str(ctx
,
1014 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1015 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1016 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1017 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1018 map
= isl_map_transitive_closure(map
, &exact
);
1022 /* Kelly et al 1996, fig 12 */
1023 map
= isl_map_read_from_str(ctx
,
1024 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1025 "1 <= i,j,j+1 <= n or "
1026 "j = n and j2 = 1 and i2 = i + 1 and "
1027 "1 <= i,i+1 <= n }", -1);
1028 map
= isl_map_transitive_closure(map
, &exact
);
1030 map2
= isl_map_read_from_str(ctx
,
1031 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1032 "1 <= i <= n and i = i2 or "
1033 "1 <= i < i2 <= n and 1 <= j <= n and "
1034 "1 <= j2 <= n }", -1);
1035 assert(isl_map_is_equal(map
, map2
));
1039 /* Omega's closure4 */
1040 map
= isl_map_read_from_str(ctx
,
1041 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1042 "1 <= x,y <= 10 or "
1043 "x2 = x + 1 and y2 = y and "
1044 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1045 map
= isl_map_transitive_closure(map
, &exact
);
1049 map
= isl_map_read_from_str(ctx
,
1050 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1051 map
= isl_map_transitive_closure(map
, &exact
);
1053 map2
= isl_map_read_from_str(ctx
,
1054 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1055 assert(isl_map_is_equal(map
, map2
));
1059 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1060 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1061 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1062 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1063 map
= isl_map_read_from_str(ctx
, str
, -1);
1064 map
= isl_map_transitive_closure(map
, &exact
);
1066 map2
= isl_map_read_from_str(ctx
, str
, -1);
1067 assert(isl_map_is_equal(map
, map2
));
1071 str
= "{[0] -> [1]; [2] -> [3]}";
1072 map
= isl_map_read_from_str(ctx
, str
, -1);
1073 map
= isl_map_transitive_closure(map
, &exact
);
1075 map2
= isl_map_read_from_str(ctx
, str
, -1);
1076 assert(isl_map_is_equal(map
, map2
));
1081 void test_lex(struct isl_ctx
*ctx
)
1086 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1087 map
= isl_map_lex_le(dim
);
1088 assert(!isl_map_is_empty(map
));
1092 void test_lexmin(struct isl_ctx
*ctx
)
1099 str
= "[p0, p1] -> { [] -> [] : "
1100 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1101 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1102 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1103 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1104 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1105 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1106 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1107 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1108 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1109 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1110 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1111 map
= isl_map_read_from_str(ctx
, str
, -1);
1112 map
= isl_map_lexmin(map
);
1115 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1116 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1117 set
= isl_set_read_from_str(ctx
, str
, -1);
1118 set
= isl_set_lexmax(set
);
1119 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1120 set2
= isl_set_read_from_str(ctx
, str
, -1);
1121 set
= isl_set_intersect(set
, set2
);
1122 assert(!isl_set_is_empty(set
));
1131 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1132 void *dep_user
, void *user
)
1134 struct must_may
*mm
= (struct must_may
*)user
;
1137 mm
->must
= isl_map_union(mm
->must
, dep
);
1139 mm
->may
= isl_map_union(mm
->may
, dep
);
1144 static int common_space(void *first
, void *second
)
1146 int depth
= *(int *)first
;
1150 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1158 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1159 equal
= isl_map_is_equal(map
, map2
);
1165 void test_dep(struct isl_ctx
*ctx
)
1170 isl_access_info
*ai
;
1177 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1178 map
= isl_map_read_from_str(ctx
, str
, -1);
1179 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1181 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1182 map
= isl_map_read_from_str(ctx
, str
, -1);
1183 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1185 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1186 map
= isl_map_read_from_str(ctx
, str
, -1);
1187 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1189 flow
= isl_access_info_compute_flow(ai
);
1190 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1191 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1192 mm
.may
= isl_map_empty(dim
);
1194 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1196 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1197 " [1,10,0] -> [2,5,0] }";
1198 assert(map_is_equal(mm
.must
, str
));
1199 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1200 assert(map_is_equal(mm
.may
, str
));
1202 isl_map_free(mm
.must
);
1203 isl_map_free(mm
.may
);
1204 isl_flow_free(flow
);
1207 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1208 map
= isl_map_read_from_str(ctx
, str
, -1);
1209 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1211 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1212 map
= isl_map_read_from_str(ctx
, str
, -1);
1213 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1215 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1216 map
= isl_map_read_from_str(ctx
, str
, -1);
1217 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1219 flow
= isl_access_info_compute_flow(ai
);
1220 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1221 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1222 mm
.may
= isl_map_empty(dim
);
1224 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1226 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1227 assert(map_is_equal(mm
.must
, str
));
1228 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1229 assert(map_is_equal(mm
.may
, str
));
1231 isl_map_free(mm
.must
);
1232 isl_map_free(mm
.may
);
1233 isl_flow_free(flow
);
1236 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1237 map
= isl_map_read_from_str(ctx
, str
, -1);
1238 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1240 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1241 map
= isl_map_read_from_str(ctx
, str
, -1);
1242 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1244 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1245 map
= isl_map_read_from_str(ctx
, str
, -1);
1246 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1248 flow
= isl_access_info_compute_flow(ai
);
1249 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1250 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1251 mm
.may
= isl_map_empty(dim
);
1253 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1255 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1256 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1257 assert(map_is_equal(mm
.may
, str
));
1258 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1259 assert(map_is_equal(mm
.must
, str
));
1261 isl_map_free(mm
.must
);
1262 isl_map_free(mm
.may
);
1263 isl_flow_free(flow
);
1266 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1267 map
= isl_map_read_from_str(ctx
, str
, -1);
1268 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1270 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1271 map
= isl_map_read_from_str(ctx
, str
, -1);
1272 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1274 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1275 map
= isl_map_read_from_str(ctx
, str
, -1);
1276 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1278 flow
= isl_access_info_compute_flow(ai
);
1279 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1280 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1281 mm
.may
= isl_map_empty(dim
);
1283 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1285 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1286 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1287 assert(map_is_equal(mm
.may
, str
));
1288 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1289 assert(map_is_equal(mm
.must
, str
));
1291 isl_map_free(mm
.must
);
1292 isl_map_free(mm
.may
);
1293 isl_flow_free(flow
);
1296 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1297 map
= isl_map_read_from_str(ctx
, str
, -1);
1298 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1300 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1301 map
= isl_map_read_from_str(ctx
, str
, -1);
1302 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1304 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1305 map
= isl_map_read_from_str(ctx
, str
, -1);
1306 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1308 flow
= isl_access_info_compute_flow(ai
);
1309 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1310 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1311 mm
.may
= isl_map_empty(dim
);
1313 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1315 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1316 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1317 assert(map_is_equal(mm
.may
, str
));
1318 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1319 assert(map_is_equal(mm
.must
, str
));
1321 isl_map_free(mm
.must
);
1322 isl_map_free(mm
.may
);
1323 isl_flow_free(flow
);
1328 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1329 map
= isl_map_read_from_str(ctx
, str
, -1);
1330 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1332 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1333 map
= isl_map_read_from_str(ctx
, str
, -1);
1334 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1336 flow
= isl_access_info_compute_flow(ai
);
1337 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1338 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1339 mm
.may
= isl_map_empty(dim
);
1341 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1343 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1344 assert(map_is_equal(mm
.must
, str
));
1345 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1346 assert(map_is_equal(mm
.may
, str
));
1348 isl_map_free(mm
.must
);
1349 isl_map_free(mm
.may
);
1350 isl_flow_free(flow
);
1353 void test_sv(struct isl_ctx
*ctx
)
1358 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1359 map
= isl_map_read_from_str(ctx
, str
, -1);
1360 assert(isl_map_is_single_valued(map
));
1363 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1364 map
= isl_map_read_from_str(ctx
, str
, -1);
1365 assert(!isl_map_is_single_valued(map
));
1369 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1373 map
= isl_map_read_from_str(ctx
, str
, -1);
1375 assert(isl_map_is_bijective(map
));
1377 assert(!isl_map_is_bijective(map
));
1381 void test_bijective(struct isl_ctx
*ctx
)
1383 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1384 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1385 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1386 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1387 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1388 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1389 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1390 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1391 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1392 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1393 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1394 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1395 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1398 void test_pwqp(struct isl_ctx
*ctx
)
1401 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1403 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1404 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1406 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1409 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1410 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1412 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1414 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1416 isl_pw_qpolynomial_free(pwqp1
);
1419 void test_split_periods(isl_ctx
*ctx
)
1422 isl_pw_qpolynomial
*pwqp
;
1424 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1425 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1426 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1427 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1429 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1432 isl_pw_qpolynomial_free(pwqp
);
1435 void test_union(isl_ctx
*ctx
)
1438 isl_union_set
*uset
;
1439 isl_union_map
*umap1
, *umap2
;
1441 str
= "{ [i] : 0 <= i <= 1 }";
1442 uset
= isl_union_set_from_set(isl_set_read_from_str(ctx
, str
, -1));
1443 str
= "{ [1] -> [0] }";
1444 umap1
= isl_union_map_from_map(isl_map_read_from_str(ctx
, str
, -1));
1446 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset
), uset
);
1447 assert(isl_union_map_is_equal(umap1
, umap2
));
1449 isl_union_map_free(umap1
);
1450 isl_union_map_free(umap2
);
1455 struct isl_ctx
*ctx
;
1457 srcdir
= getenv("srcdir");
1460 ctx
= isl_ctx_alloc();
1462 test_split_periods(ctx
);
1467 test_bijective(ctx
);
1471 test_construction(ctx
);
1474 test_application(ctx
);
1475 test_affine_hull(ctx
);
1476 test_convex_hull(ctx
);