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]]}");
48 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
49 map
= isl_map_read_from_str(ctx
, str
, -1);
50 str
= "{ [new, old] -> [o0, o1] : "
51 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
52 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
53 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
54 map2
= isl_map_read_from_str(ctx
, str
, -1);
55 assert(isl_map_is_equal(map
, map2
));
60 void test_read(struct isl_ctx
*ctx
)
62 char filename
[PATH_MAX
];
65 struct isl_basic_set
*bset1
, *bset2
;
66 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
68 n
= snprintf(filename
, sizeof(filename
),
69 "%s/test_inputs/set.omega", srcdir
);
70 assert(n
< sizeof(filename
));
71 input
= fopen(filename
, "r");
74 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
75 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
77 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
79 isl_basic_set_free(bset1
);
80 isl_basic_set_free(bset2
);
85 void test_bounded(struct isl_ctx
*ctx
)
90 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
91 bounded
= isl_set_is_bounded(set
);
95 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
96 bounded
= isl_set_is_bounded(set
);
100 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
101 bounded
= isl_set_is_bounded(set
);
106 /* Construct the basic set { [i] : 5 <= i <= N } */
107 void test_construction(struct isl_ctx
*ctx
)
111 struct isl_basic_set
*bset
;
112 struct isl_constraint
*c
;
116 dim
= isl_dim_set_alloc(ctx
, 1, 1);
117 bset
= isl_basic_set_universe(dim
);
119 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
120 isl_int_set_si(v
, -1);
121 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
122 isl_int_set_si(v
, 1);
123 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
124 bset
= isl_basic_set_add_constraint(bset
, c
);
126 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
127 isl_int_set_si(v
, 1);
128 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
129 isl_int_set_si(v
, -5);
130 isl_constraint_set_constant(c
, v
);
131 bset
= isl_basic_set_add_constraint(bset
, c
);
133 isl_basic_set_free(bset
);
138 void test_dim(struct isl_ctx
*ctx
)
141 isl_map
*map1
, *map2
;
143 map1
= isl_map_read_from_str(ctx
,
144 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
145 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
146 map2
= isl_map_read_from_str(ctx
,
147 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
148 assert(isl_map_is_equal(map1
, map2
));
151 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
152 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
153 assert(isl_map_is_equal(map1
, map2
));
158 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
159 map1
= isl_map_read_from_str(ctx
, str
, -1);
160 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
161 map2
= isl_map_read_from_str(ctx
, str
, -1);
162 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
163 assert(isl_map_is_equal(map1
, map2
));
169 void test_div(struct isl_ctx
*ctx
)
175 struct isl_basic_set
*bset
;
176 struct isl_constraint
*c
;
181 dim
= isl_dim_set_alloc(ctx
, 0, 1);
182 bset
= isl_basic_set_universe(dim
);
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 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
196 isl_int_set_si(v
, 1);
197 isl_constraint_set_constant(c
, v
);
198 isl_int_set_si(v
, -1);
199 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
200 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
201 c
= isl_constraint_add_div(c
, div
, &pos
);
202 isl_int_set_si(v
, 3);
203 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
204 bset
= isl_basic_set_add_constraint(bset
, c
);
206 assert(bset
&& bset
->n_div
== 1);
207 isl_basic_set_free(bset
);
210 dim
= isl_dim_set_alloc(ctx
, 0, 1);
211 bset
= isl_basic_set_universe(dim
);
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 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
225 isl_int_set_si(v
, -1);
226 isl_constraint_set_constant(c
, v
);
227 isl_int_set_si(v
, 1);
228 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
229 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
230 c
= isl_constraint_add_div(c
, div
, &pos
);
231 isl_int_set_si(v
, 3);
232 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
233 bset
= isl_basic_set_add_constraint(bset
, c
);
235 assert(bset
&& bset
->n_div
== 1);
236 isl_basic_set_free(bset
);
239 dim
= isl_dim_set_alloc(ctx
, 0, 1);
240 bset
= isl_basic_set_universe(dim
);
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
, 3);
250 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
251 bset
= isl_basic_set_add_constraint(bset
, c
);
253 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
254 isl_int_set_si(v
, -3);
255 isl_constraint_set_constant(c
, v
);
256 isl_int_set_si(v
, 1);
257 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
258 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
259 c
= isl_constraint_add_div(c
, div
, &pos
);
260 isl_int_set_si(v
, 4);
261 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
262 bset
= isl_basic_set_add_constraint(bset
, c
);
264 assert(bset
&& bset
->n_div
== 1);
265 isl_basic_set_free(bset
);
268 dim
= isl_dim_set_alloc(ctx
, 0, 1);
269 bset
= isl_basic_set_universe(dim
);
271 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
272 isl_int_set_si(v
, 2);
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
, 3);
279 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
280 bset
= isl_basic_set_add_constraint(bset
, c
);
282 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
283 isl_int_set_si(v
, -1);
284 isl_constraint_set_constant(c
, v
);
285 isl_int_set_si(v
, 1);
286 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
287 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
288 c
= isl_constraint_add_div(c
, div
, &pos
);
289 isl_int_set_si(v
, 6);
290 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
291 bset
= isl_basic_set_add_constraint(bset
, c
);
293 assert(isl_basic_set_is_empty(bset
));
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
, 3);
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
== 0);
317 isl_basic_set_free(bset
);
320 dim
= isl_dim_set_alloc(ctx
, 0, 2);
321 bset
= isl_basic_set_universe(dim
);
323 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
324 isl_int_set_si(v
, -1);
325 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
326 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
327 c
= isl_constraint_add_div(c
, div
, &pos
);
328 isl_int_set_si(v
, 6);
329 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
330 bset
= isl_basic_set_add_constraint(bset
, c
);
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 bset
= isl_basic_set_add_constraint(bset
, c
);
339 assert(bset
&& bset
->n_div
== 1);
340 isl_basic_set_free(bset
);
343 /* This test is a bit tricky. We set up an equality
345 * Normalization of divs creates _two_ divs
348 * Afterwards e0 is removed again because it has coefficient -1
349 * and we end up with the original equality and div again.
350 * Perhaps we can avoid the introduction of this temporary div.
352 dim
= isl_dim_set_alloc(ctx
, 0, 3);
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
, 2, 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 /* Test disabled for now */
370 assert(bset && bset->n_div == 1);
372 isl_basic_set_free(bset
);
375 dim
= isl_dim_set_alloc(ctx
, 0, 4);
376 bset
= isl_basic_set_universe(dim
);
378 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
379 isl_int_set_si(v
, -1);
380 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
381 isl_int_set_si(v
, -3);
382 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
383 isl_int_set_si(v
, -3);
384 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
385 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
386 c
= isl_constraint_add_div(c
, div
, &pos
);
387 isl_int_set_si(v
, 6);
388 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
389 bset
= isl_basic_set_add_constraint(bset
, c
);
391 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
392 isl_int_set_si(v
, -1);
393 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
394 isl_int_set_si(v
, 1);
395 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
396 isl_int_set_si(v
, 1);
397 isl_constraint_set_constant(c
, v
);
398 bset
= isl_basic_set_add_constraint(bset
, c
);
400 /* Test disabled for now */
402 assert(bset && bset->n_div == 1);
404 isl_basic_set_free(bset
);
407 dim
= isl_dim_set_alloc(ctx
, 0, 2);
408 bset
= isl_basic_set_universe(dim
);
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 isl_int_set_si(v
, -1);
414 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
415 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
416 c
= isl_constraint_add_div(c
, div
, &pos
);
417 isl_int_set_si(v
, -2);
418 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
419 bset
= isl_basic_set_add_constraint(bset
, c
);
421 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
422 isl_int_set_si(v
, -1);
423 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
424 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
425 c
= isl_constraint_add_div(c
, div
, &pos
);
426 isl_int_set_si(v
, 3);
427 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
428 isl_int_set_si(v
, 2);
429 isl_constraint_set_constant(c
, v
);
430 bset
= isl_basic_set_add_constraint(bset
, c
);
432 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
434 assert(!isl_basic_set_is_empty(bset
));
436 isl_basic_set_free(bset
);
439 dim
= isl_dim_set_alloc(ctx
, 0, 2);
440 bset
= isl_basic_set_universe(dim
);
442 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
443 isl_int_set_si(v
, 1);
444 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
445 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
446 c
= isl_constraint_add_div(c
, div
, &pos
);
447 isl_int_set_si(v
, -2);
448 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
449 bset
= isl_basic_set_add_constraint(bset
, c
);
451 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
453 isl_basic_set_free(bset
);
458 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
460 char filename
[PATH_MAX
];
463 struct isl_basic_set
*bset1
, *bset2
;
464 struct isl_basic_map
*bmap
;
466 n
= snprintf(filename
, sizeof(filename
),
467 "%s/test_inputs/%s.omega", srcdir
, name
);
468 assert(n
< sizeof(filename
));
469 input
= fopen(filename
, "r");
472 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
473 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
475 bset1
= isl_basic_set_apply(bset1
, bmap
);
477 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
479 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
481 isl_basic_set_free(bset1
);
482 isl_basic_set_free(bset2
);
487 void test_application(struct isl_ctx
*ctx
)
489 test_application_case(ctx
, "application");
490 test_application_case(ctx
, "application2");
493 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
495 char filename
[PATH_MAX
];
498 struct isl_basic_set
*bset1
, *bset2
;
500 n
= snprintf(filename
, sizeof(filename
),
501 "%s/test_inputs/%s.polylib", srcdir
, name
);
502 assert(n
< sizeof(filename
));
503 input
= fopen(filename
, "r");
506 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
507 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
509 bset1
= isl_basic_set_affine_hull(bset1
);
511 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
513 isl_basic_set_free(bset1
);
514 isl_basic_set_free(bset2
);
519 void test_affine_hull(struct isl_ctx
*ctx
)
521 test_affine_hull_case(ctx
, "affine2");
522 test_affine_hull_case(ctx
, "affine");
523 test_affine_hull_case(ctx
, "affine3");
526 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
528 char filename
[PATH_MAX
];
531 struct isl_basic_set
*bset1
, *bset2
;
534 n
= snprintf(filename
, sizeof(filename
),
535 "%s/test_inputs/%s.polylib", srcdir
, name
);
536 assert(n
< sizeof(filename
));
537 input
= fopen(filename
, "r");
540 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
541 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
543 set
= isl_basic_set_union(bset1
, bset2
);
544 bset1
= isl_set_convex_hull(set
);
546 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
548 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
550 isl_basic_set_free(bset1
);
551 isl_basic_set_free(bset2
);
556 void test_convex_hull(struct isl_ctx
*ctx
)
558 const char *str1
, *str2
;
559 isl_set
*set1
, *set2
;
561 test_convex_hull_case(ctx
, "convex0");
562 test_convex_hull_case(ctx
, "convex1");
563 test_convex_hull_case(ctx
, "convex2");
564 test_convex_hull_case(ctx
, "convex3");
565 test_convex_hull_case(ctx
, "convex4");
566 test_convex_hull_case(ctx
, "convex5");
567 test_convex_hull_case(ctx
, "convex6");
568 test_convex_hull_case(ctx
, "convex7");
569 test_convex_hull_case(ctx
, "convex8");
570 test_convex_hull_case(ctx
, "convex9");
571 test_convex_hull_case(ctx
, "convex10");
572 test_convex_hull_case(ctx
, "convex11");
573 test_convex_hull_case(ctx
, "convex12");
574 test_convex_hull_case(ctx
, "convex13");
575 test_convex_hull_case(ctx
, "convex14");
576 test_convex_hull_case(ctx
, "convex15");
578 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
579 "(i0 = 1 and i1 = 0 and i2 = 1) or "
580 "(i0 = 0 and i1 = 0 and i2 = 0) }";
581 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
582 set1
= isl_set_read_from_str(ctx
, str1
, -1);
583 set2
= isl_set_read_from_str(ctx
, str2
, -1);
584 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
585 assert(isl_set_is_equal(set1
, set2
));
590 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
592 char filename
[PATH_MAX
];
595 struct isl_basic_set
*bset1
, *bset2
;
597 n
= snprintf(filename
, sizeof(filename
),
598 "%s/test_inputs/%s.polylib", srcdir
, name
);
599 assert(n
< sizeof(filename
));
600 input
= fopen(filename
, "r");
603 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
604 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
606 bset1
= isl_basic_set_gist(bset1
, bset2
);
608 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
610 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
612 isl_basic_set_free(bset1
);
613 isl_basic_set_free(bset2
);
618 void test_gist(struct isl_ctx
*ctx
)
620 test_gist_case(ctx
, "gist1");
623 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
627 set
= isl_set_read_from_str(ctx
, str
, -1);
628 set
= isl_set_coalesce(set
);
629 set2
= isl_set_read_from_str(ctx
, str
, -1);
630 assert(isl_set_is_equal(set
, set2
));
632 assert(set
&& set
->n
== 1);
637 void test_coalesce(struct isl_ctx
*ctx
)
640 struct isl_set
*set
, *set2
;
641 struct isl_map
*map
, *map2
;
643 set
= isl_set_read_from_str(ctx
,
644 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
645 "y >= x & x >= 2 & 5 >= y }", -1);
646 set
= isl_set_coalesce(set
);
647 assert(set
&& set
->n
== 1);
650 set
= isl_set_read_from_str(ctx
,
651 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
652 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
653 set
= isl_set_coalesce(set
);
654 assert(set
&& set
->n
== 1);
657 set
= isl_set_read_from_str(ctx
,
658 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
659 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
660 set
= isl_set_coalesce(set
);
661 assert(set
&& set
->n
== 2);
664 set
= isl_set_read_from_str(ctx
,
665 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
666 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
667 set
= isl_set_coalesce(set
);
668 assert(set
&& set
->n
== 1);
671 set
= isl_set_read_from_str(ctx
,
672 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
673 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
674 set
= isl_set_coalesce(set
);
675 assert(set
&& set
->n
== 2);
678 set
= isl_set_read_from_str(ctx
,
679 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
680 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
681 set
= isl_set_coalesce(set
);
682 assert(set
&& set
->n
== 2);
685 set
= isl_set_read_from_str(ctx
,
686 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
687 "y >= 0 & x = 6 & y <= 6}", -1);
688 set
= isl_set_coalesce(set
);
689 assert(set
&& set
->n
== 1);
692 set
= isl_set_read_from_str(ctx
,
693 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
694 "y >= 0 & x = 7 & y <= 6}", -1);
695 set
= isl_set_coalesce(set
);
696 assert(set
&& set
->n
== 2);
699 set
= isl_set_read_from_str(ctx
,
700 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
701 "y >= 0 & x = 6 & y <= 5}", -1);
702 set
= isl_set_coalesce(set
);
703 assert(set
&& set
->n
== 1);
704 set2
= isl_set_read_from_str(ctx
,
705 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
706 "y >= 0 & x = 6 & y <= 5}", -1);
707 assert(isl_set_is_equal(set
, set2
));
711 set
= isl_set_read_from_str(ctx
,
712 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
713 "y >= 0 & x = 6 & y <= 7}", -1);
714 set
= isl_set_coalesce(set
);
715 assert(set
&& set
->n
== 2);
718 set
= isl_set_read_from_str(ctx
,
719 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
720 set
= isl_set_coalesce(set
);
721 assert(set
&& set
->n
== 1);
722 set2
= isl_set_read_from_str(ctx
,
723 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
724 assert(isl_set_is_equal(set
, set2
));
728 set
= isl_set_read_from_str(ctx
,
729 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
730 set
= isl_set_coalesce(set
);
731 set2
= isl_set_read_from_str(ctx
,
732 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
733 assert(isl_set_is_equal(set
, set2
));
737 set
= isl_set_read_from_str(ctx
,
738 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
739 "2 <= i and i <= n }", -1);
740 set
= isl_set_coalesce(set
);
741 assert(set
&& set
->n
== 1);
742 set2
= isl_set_read_from_str(ctx
,
743 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
744 "2 <= i and i <= n }", -1);
745 assert(isl_set_is_equal(set
, set2
));
749 map
= isl_map_read_from_str(ctx
,
750 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
751 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
752 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
753 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
754 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
755 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
756 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
757 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
758 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
759 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
760 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
761 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
762 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
763 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
764 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
765 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
766 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
767 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
768 map
= isl_map_coalesce(map
);
769 map2
= isl_map_read_from_str(ctx
,
770 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
771 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
772 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
773 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
774 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
775 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
776 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
777 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
778 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
779 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
780 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
781 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
782 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
783 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
784 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
785 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
786 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
787 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
788 assert(isl_map_is_equal(map
, map2
));
792 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
793 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
794 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
795 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
796 map
= isl_map_read_from_str(ctx
, str
, -1);
797 map
= isl_map_coalesce(map
);
798 map2
= isl_map_read_from_str(ctx
, str
, -1);
799 assert(isl_map_is_equal(map
, map2
));
803 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
804 "[o0, o1, o2, o3, o4, o5, o6] : "
805 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
806 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
807 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
808 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
809 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
810 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
811 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
812 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
813 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
814 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
815 "o6 >= i3 + i6 - o3 and M >= 0 and "
816 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
817 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
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
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
826 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
827 "(o0 = 0 and M >= 2 and N >= 3) or "
828 "(M = 0 and o0 = 0 and N >= 3) }";
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 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
837 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
838 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
839 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
840 map
= isl_map_read_from_str(ctx
, str
, -1);
841 map
= isl_map_coalesce(map
);
842 map2
= isl_map_read_from_str(ctx
, str
, -1);
843 assert(isl_map_is_equal(map
, map2
));
847 test_coalesce_set(ctx
,
848 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
849 "(i1 = M and M >= 1) }", 0);
850 test_coalesce_set(ctx
,
851 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
852 test_coalesce_set(ctx
,
853 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
854 "(y = 3 and x = 1) }", 1);
855 test_coalesce_set(ctx
,
856 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
857 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
858 "i1 <= M and i3 <= M and i4 <= M) or "
859 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
860 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
861 "i4 <= -1 + M) }", 1);
862 test_coalesce_set(ctx
,
863 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
864 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
865 test_coalesce_set(ctx
,
866 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
867 "-x - y + 1 >= 0 and -3 <= z <= 3;"
868 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
869 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
870 test_coalesce_set(ctx
,
871 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
872 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
873 test_coalesce_set(ctx
,
874 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
875 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
878 void test_closure(struct isl_ctx
*ctx
)
886 /* COCOA example 1 */
887 map
= isl_map_read_from_str(ctx
,
888 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
889 "1 <= i and i < n and 1 <= j and j < n or "
890 "i2 = i + 1 and j2 = j - 1 and "
891 "1 <= i and i < n and 2 <= j and j <= n }", -1);
892 map
= isl_map_power(map
, 1, &exact
);
896 /* COCOA example 1 */
897 map
= isl_map_read_from_str(ctx
,
898 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
899 "1 <= i and i < n and 1 <= j and j < n or "
900 "i2 = i + 1 and j2 = j - 1 and "
901 "1 <= i and i < n and 2 <= j and j <= n }", -1);
902 map
= isl_map_transitive_closure(map
, &exact
);
904 map2
= isl_map_read_from_str(ctx
,
905 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
906 "1 <= i and i < n and 1 <= j and j <= n and "
907 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
908 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
909 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
910 assert(isl_map_is_equal(map
, map2
));
914 map
= isl_map_read_from_str(ctx
,
915 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
916 " 0 <= y and y <= n }", -1);
917 map
= isl_map_transitive_closure(map
, &exact
);
918 map2
= isl_map_read_from_str(ctx
,
919 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
920 " 0 <= y and y <= n }", -1);
921 assert(isl_map_is_equal(map
, map2
));
925 /* COCOA example 2 */
926 map
= isl_map_read_from_str(ctx
,
927 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
928 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
929 "i2 = i + 2 and j2 = j - 2 and "
930 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
931 map
= isl_map_transitive_closure(map
, &exact
);
933 map2
= isl_map_read_from_str(ctx
,
934 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
935 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
936 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
937 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
938 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
939 assert(isl_map_is_equal(map
, map2
));
943 /* COCOA Fig.2 left */
944 map
= isl_map_read_from_str(ctx
,
945 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
946 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
948 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
949 "j <= 2 i - 3 and j <= n - 2 or "
950 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
951 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
952 map
= isl_map_transitive_closure(map
, &exact
);
956 /* COCOA Fig.2 right */
957 map
= isl_map_read_from_str(ctx
,
958 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
959 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
961 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
962 "j <= 2 i - 4 and j <= n - 3 or "
963 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
964 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
965 map
= isl_map_power(map
, 1, &exact
);
969 /* COCOA Fig.2 right */
970 map
= isl_map_read_from_str(ctx
,
971 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
972 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
974 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
975 "j <= 2 i - 4 and j <= n - 3 or "
976 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
977 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
978 map
= isl_map_transitive_closure(map
, &exact
);
980 map2
= isl_map_read_from_str(ctx
,
981 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
982 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
983 "j <= n and 3 + i + 2 j <= 3 n and "
984 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
985 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
986 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
987 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
988 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
989 assert(isl_map_is_equal(map
, map2
));
993 /* COCOA Fig.1 right */
994 dom
= isl_set_read_from_str(ctx
,
995 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
996 "2 x - 3 y + 3 >= 0 }", -1);
997 right
= isl_map_read_from_str(ctx
,
998 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
999 up
= isl_map_read_from_str(ctx
,
1000 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1001 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1002 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1003 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1004 up
= isl_map_intersect_range(up
, dom
);
1005 map
= isl_map_union(up
, right
);
1006 map
= isl_map_transitive_closure(map
, &exact
);
1008 map2
= isl_map_read_from_str(ctx
,
1009 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1010 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1011 assert(isl_map_is_equal(map
, map2
));
1015 /* COCOA Theorem 1 counter example */
1016 map
= isl_map_read_from_str(ctx
,
1017 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1018 "i2 = 1 and j2 = j or "
1019 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1020 map
= isl_map_transitive_closure(map
, &exact
);
1024 map
= isl_map_read_from_str(ctx
,
1025 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1026 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1027 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1028 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1029 map
= isl_map_transitive_closure(map
, &exact
);
1033 /* Kelly et al 1996, fig 12 */
1034 map
= isl_map_read_from_str(ctx
,
1035 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1036 "1 <= i,j,j+1 <= n or "
1037 "j = n and j2 = 1 and i2 = i + 1 and "
1038 "1 <= i,i+1 <= n }", -1);
1039 map
= isl_map_transitive_closure(map
, &exact
);
1041 map2
= isl_map_read_from_str(ctx
,
1042 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1043 "1 <= i <= n and i = i2 or "
1044 "1 <= i < i2 <= n and 1 <= j <= n and "
1045 "1 <= j2 <= n }", -1);
1046 assert(isl_map_is_equal(map
, map2
));
1050 /* Omega's closure4 */
1051 map
= isl_map_read_from_str(ctx
,
1052 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1053 "1 <= x,y <= 10 or "
1054 "x2 = x + 1 and y2 = y and "
1055 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1056 map
= isl_map_transitive_closure(map
, &exact
);
1060 map
= isl_map_read_from_str(ctx
,
1061 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1062 map
= isl_map_transitive_closure(map
, &exact
);
1064 map2
= isl_map_read_from_str(ctx
,
1065 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1066 assert(isl_map_is_equal(map
, map2
));
1070 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1071 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1072 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1073 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1074 map
= isl_map_read_from_str(ctx
, str
, -1);
1075 map
= isl_map_transitive_closure(map
, &exact
);
1077 map2
= isl_map_read_from_str(ctx
, str
, -1);
1078 assert(isl_map_is_equal(map
, map2
));
1082 str
= "{[0] -> [1]; [2] -> [3]}";
1083 map
= isl_map_read_from_str(ctx
, str
, -1);
1084 map
= isl_map_transitive_closure(map
, &exact
);
1086 map2
= isl_map_read_from_str(ctx
, str
, -1);
1087 assert(isl_map_is_equal(map
, map2
));
1092 void test_lex(struct isl_ctx
*ctx
)
1097 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1098 map
= isl_map_lex_le(dim
);
1099 assert(!isl_map_is_empty(map
));
1103 void test_lexmin(struct isl_ctx
*ctx
)
1110 str
= "[p0, p1] -> { [] -> [] : "
1111 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1112 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1113 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1114 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1115 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1116 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1117 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1118 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1119 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1120 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1121 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1122 map
= isl_map_read_from_str(ctx
, str
, -1);
1123 map
= isl_map_lexmin(map
);
1126 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1127 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1128 set
= isl_set_read_from_str(ctx
, str
, -1);
1129 set
= isl_set_lexmax(set
);
1130 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1131 set2
= isl_set_read_from_str(ctx
, str
, -1);
1132 set
= isl_set_intersect(set
, set2
);
1133 assert(!isl_set_is_empty(set
));
1142 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1143 void *dep_user
, void *user
)
1145 struct must_may
*mm
= (struct must_may
*)user
;
1148 mm
->must
= isl_map_union(mm
->must
, dep
);
1150 mm
->may
= isl_map_union(mm
->may
, dep
);
1155 static int common_space(void *first
, void *second
)
1157 int depth
= *(int *)first
;
1161 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1169 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1170 equal
= isl_map_is_equal(map
, map2
);
1176 void test_dep(struct isl_ctx
*ctx
)
1181 isl_access_info
*ai
;
1188 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1189 map
= isl_map_read_from_str(ctx
, str
, -1);
1190 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1192 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1193 map
= isl_map_read_from_str(ctx
, str
, -1);
1194 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1196 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1197 map
= isl_map_read_from_str(ctx
, str
, -1);
1198 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1200 flow
= isl_access_info_compute_flow(ai
);
1201 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1202 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1203 mm
.may
= isl_map_empty(dim
);
1205 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1207 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1208 " [1,10,0] -> [2,5,0] }";
1209 assert(map_is_equal(mm
.must
, str
));
1210 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1211 assert(map_is_equal(mm
.may
, str
));
1213 isl_map_free(mm
.must
);
1214 isl_map_free(mm
.may
);
1215 isl_flow_free(flow
);
1218 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1219 map
= isl_map_read_from_str(ctx
, str
, -1);
1220 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1222 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1223 map
= isl_map_read_from_str(ctx
, str
, -1);
1224 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1226 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1227 map
= isl_map_read_from_str(ctx
, str
, -1);
1228 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1230 flow
= isl_access_info_compute_flow(ai
);
1231 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1232 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1233 mm
.may
= isl_map_empty(dim
);
1235 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1237 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1238 assert(map_is_equal(mm
.must
, str
));
1239 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1240 assert(map_is_equal(mm
.may
, str
));
1242 isl_map_free(mm
.must
);
1243 isl_map_free(mm
.may
);
1244 isl_flow_free(flow
);
1247 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1248 map
= isl_map_read_from_str(ctx
, str
, -1);
1249 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1251 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1252 map
= isl_map_read_from_str(ctx
, str
, -1);
1253 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1255 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1256 map
= isl_map_read_from_str(ctx
, str
, -1);
1257 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1259 flow
= isl_access_info_compute_flow(ai
);
1260 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1261 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1262 mm
.may
= isl_map_empty(dim
);
1264 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1266 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1267 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1268 assert(map_is_equal(mm
.may
, str
));
1269 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1270 assert(map_is_equal(mm
.must
, str
));
1272 isl_map_free(mm
.must
);
1273 isl_map_free(mm
.may
);
1274 isl_flow_free(flow
);
1277 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1278 map
= isl_map_read_from_str(ctx
, str
, -1);
1279 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1281 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1282 map
= isl_map_read_from_str(ctx
, str
, -1);
1283 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1285 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1286 map
= isl_map_read_from_str(ctx
, str
, -1);
1287 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1289 flow
= isl_access_info_compute_flow(ai
);
1290 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1291 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1292 mm
.may
= isl_map_empty(dim
);
1294 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1296 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1297 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1298 assert(map_is_equal(mm
.may
, str
));
1299 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1300 assert(map_is_equal(mm
.must
, str
));
1302 isl_map_free(mm
.must
);
1303 isl_map_free(mm
.may
);
1304 isl_flow_free(flow
);
1307 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1308 map
= isl_map_read_from_str(ctx
, str
, -1);
1309 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1311 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1312 map
= isl_map_read_from_str(ctx
, str
, -1);
1313 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1315 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1316 map
= isl_map_read_from_str(ctx
, str
, -1);
1317 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1319 flow
= isl_access_info_compute_flow(ai
);
1320 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1321 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1322 mm
.may
= isl_map_empty(dim
);
1324 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1326 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1327 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1328 assert(map_is_equal(mm
.may
, str
));
1329 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1330 assert(map_is_equal(mm
.must
, str
));
1332 isl_map_free(mm
.must
);
1333 isl_map_free(mm
.may
);
1334 isl_flow_free(flow
);
1339 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1340 map
= isl_map_read_from_str(ctx
, str
, -1);
1341 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1343 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1344 map
= isl_map_read_from_str(ctx
, str
, -1);
1345 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1347 flow
= isl_access_info_compute_flow(ai
);
1348 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1349 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1350 mm
.may
= isl_map_empty(dim
);
1352 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1354 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1355 assert(map_is_equal(mm
.must
, str
));
1356 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1357 assert(map_is_equal(mm
.may
, str
));
1359 isl_map_free(mm
.must
);
1360 isl_map_free(mm
.may
);
1361 isl_flow_free(flow
);
1364 void test_sv(struct isl_ctx
*ctx
)
1369 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1370 map
= isl_map_read_from_str(ctx
, str
, -1);
1371 assert(isl_map_is_single_valued(map
));
1374 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1375 map
= isl_map_read_from_str(ctx
, str
, -1);
1376 assert(!isl_map_is_single_valued(map
));
1380 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1384 map
= isl_map_read_from_str(ctx
, str
, -1);
1386 assert(isl_map_is_bijective(map
));
1388 assert(!isl_map_is_bijective(map
));
1392 void test_bijective(struct isl_ctx
*ctx
)
1394 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1395 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1396 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1397 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1398 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1399 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1400 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1401 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1402 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1403 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1404 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1405 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1406 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1409 void test_pwqp(struct isl_ctx
*ctx
)
1413 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1415 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1416 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1418 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1421 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1422 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1424 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1426 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1428 isl_pw_qpolynomial_free(pwqp1
);
1430 str
= "{ [i] -> i }";
1431 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1432 str
= "{ [k] : exists a : k = 2a }";
1433 set
= isl_set_read_from_str(ctx
, str
, 0);
1434 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1435 str
= "{ [i] -> i }";
1436 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1438 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1440 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1442 isl_pw_qpolynomial_free(pwqp1
);
1445 void test_split_periods(isl_ctx
*ctx
)
1448 isl_pw_qpolynomial
*pwqp
;
1450 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1451 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1452 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1453 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1455 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1458 isl_pw_qpolynomial_free(pwqp
);
1461 void test_union(isl_ctx
*ctx
)
1464 isl_union_set
*uset
;
1465 isl_union_map
*umap1
, *umap2
;
1467 str
= "{ [i] : 0 <= i <= 1 }";
1468 uset
= isl_union_set_from_set(isl_set_read_from_str(ctx
, str
, -1));
1469 str
= "{ [1] -> [0] }";
1470 umap1
= isl_union_map_from_map(isl_map_read_from_str(ctx
, str
, -1));
1472 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset
), uset
);
1473 assert(isl_union_map_is_equal(umap1
, umap2
));
1475 isl_union_map_free(umap1
);
1476 isl_union_map_free(umap2
);
1481 struct isl_ctx
*ctx
;
1483 srcdir
= getenv("srcdir");
1486 ctx
= isl_ctx_alloc();
1488 test_split_periods(ctx
);
1493 test_bijective(ctx
);
1497 test_construction(ctx
);
1500 test_application(ctx
);
1501 test_affine_hull(ctx
);
1502 test_convex_hull(ctx
);