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
15 #include <isl_constraint.h>
19 void test_read(struct isl_ctx
*ctx
)
21 char filename
[PATH_MAX
];
24 struct isl_basic_set
*bset1
, *bset2
;
25 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
27 n
= snprintf(filename
, sizeof(filename
),
28 "%s/test_inputs/set.omega", srcdir
);
29 assert(n
< sizeof(filename
));
30 input
= fopen(filename
, "r");
33 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
34 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
36 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
38 isl_basic_set_free(bset1
);
39 isl_basic_set_free(bset2
);
44 /* Construct the basic set { [i] : 5 <= i <= N } */
45 void test_construction(struct isl_ctx
*ctx
)
49 struct isl_basic_set
*bset
;
50 struct isl_constraint
*c
;
54 dim
= isl_dim_set_alloc(ctx
, 1, 1);
55 bset
= isl_basic_set_universe(dim
);
57 c
= isl_inequality_alloc(isl_dim_copy(bset
->dim
));
58 isl_int_set_si(v
, -1);
59 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
61 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
62 bset
= isl_basic_set_add_constraint(bset
, c
);
64 c
= isl_inequality_alloc(isl_dim_copy(bset
->dim
));
66 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
67 isl_int_set_si(v
, -5);
68 isl_constraint_set_constant(c
, v
);
69 bset
= isl_basic_set_add_constraint(bset
, c
);
71 isl_basic_set_free(bset
);
76 void test_dim(struct isl_ctx
*ctx
)
80 map1
= isl_map_read_from_str(ctx
,
81 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
82 map1
= isl_map_add(map1
, isl_dim_in
, 1);
83 map2
= isl_map_read_from_str(ctx
,
84 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
85 assert(isl_map_is_equal(map1
, map2
));
88 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
89 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
90 assert(isl_map_is_equal(map1
, map2
));
96 void test_div(struct isl_ctx
*ctx
)
102 struct isl_basic_set
*bset
;
103 struct isl_constraint
*c
;
108 dim
= isl_dim_set_alloc(ctx
, 0, 1);
109 bset
= isl_basic_set_universe(dim
);
111 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
112 isl_int_set_si(v
, -1);
113 isl_constraint_set_constant(c
, v
);
114 isl_int_set_si(v
, 1);
115 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
116 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
117 c
= isl_constraint_add_div(c
, div
, &pos
);
118 isl_int_set_si(v
, 3);
119 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
120 bset
= isl_basic_set_add_constraint(bset
, c
);
122 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
123 isl_int_set_si(v
, 1);
124 isl_constraint_set_constant(c
, v
);
125 isl_int_set_si(v
, -1);
126 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
127 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
128 c
= isl_constraint_add_div(c
, div
, &pos
);
129 isl_int_set_si(v
, 3);
130 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
131 bset
= isl_basic_set_add_constraint(bset
, c
);
133 assert(bset
->n_div
== 1);
134 isl_basic_set_free(bset
);
137 dim
= isl_dim_set_alloc(ctx
, 0, 1);
138 bset
= isl_basic_set_universe(dim
);
140 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
141 isl_int_set_si(v
, 1);
142 isl_constraint_set_constant(c
, v
);
143 isl_int_set_si(v
, -1);
144 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
145 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
146 c
= isl_constraint_add_div(c
, div
, &pos
);
147 isl_int_set_si(v
, 3);
148 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
149 bset
= isl_basic_set_add_constraint(bset
, c
);
151 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
152 isl_int_set_si(v
, -1);
153 isl_constraint_set_constant(c
, v
);
154 isl_int_set_si(v
, 1);
155 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
156 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
157 c
= isl_constraint_add_div(c
, div
, &pos
);
158 isl_int_set_si(v
, 3);
159 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
160 bset
= isl_basic_set_add_constraint(bset
, c
);
162 assert(bset
->n_div
== 1);
163 isl_basic_set_free(bset
);
166 dim
= isl_dim_set_alloc(ctx
, 0, 1);
167 bset
= isl_basic_set_universe(dim
);
169 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
170 isl_int_set_si(v
, 1);
171 isl_constraint_set_constant(c
, v
);
172 isl_int_set_si(v
, -1);
173 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
174 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
175 c
= isl_constraint_add_div(c
, div
, &pos
);
176 isl_int_set_si(v
, 3);
177 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
178 bset
= isl_basic_set_add_constraint(bset
, c
);
180 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
181 isl_int_set_si(v
, -3);
182 isl_constraint_set_constant(c
, v
);
183 isl_int_set_si(v
, 1);
184 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
185 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
186 c
= isl_constraint_add_div(c
, div
, &pos
);
187 isl_int_set_si(v
, 4);
188 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
189 bset
= isl_basic_set_add_constraint(bset
, c
);
191 assert(bset
->n_div
== 1);
192 isl_basic_set_free(bset
);
195 dim
= isl_dim_set_alloc(ctx
, 0, 1);
196 bset
= isl_basic_set_universe(dim
);
198 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
199 isl_int_set_si(v
, 2);
200 isl_constraint_set_constant(c
, v
);
201 isl_int_set_si(v
, -1);
202 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
203 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
204 c
= isl_constraint_add_div(c
, div
, &pos
);
205 isl_int_set_si(v
, 3);
206 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
207 bset
= isl_basic_set_add_constraint(bset
, c
);
209 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
210 isl_int_set_si(v
, -1);
211 isl_constraint_set_constant(c
, v
);
212 isl_int_set_si(v
, 1);
213 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
214 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
215 c
= isl_constraint_add_div(c
, div
, &pos
);
216 isl_int_set_si(v
, 6);
217 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
218 bset
= isl_basic_set_add_constraint(bset
, c
);
220 assert(isl_basic_set_is_empty(bset
));
221 isl_basic_set_free(bset
);
224 dim
= isl_dim_set_alloc(ctx
, 0, 2);
225 bset
= isl_basic_set_universe(dim
);
227 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
228 isl_int_set_si(v
, -1);
229 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
230 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
231 c
= isl_constraint_add_div(c
, div
, &pos
);
232 isl_int_set_si(v
, 3);
233 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
234 bset
= isl_basic_set_add_constraint(bset
, c
);
236 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
237 isl_int_set_si(v
, 1);
238 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
239 isl_int_set_si(v
, -3);
240 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
241 bset
= isl_basic_set_add_constraint(bset
, c
);
243 assert(bset
->n_div
== 0);
244 isl_basic_set_free(bset
);
247 dim
= isl_dim_set_alloc(ctx
, 0, 2);
248 bset
= isl_basic_set_universe(dim
);
250 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
251 isl_int_set_si(v
, -1);
252 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
253 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
254 c
= isl_constraint_add_div(c
, div
, &pos
);
255 isl_int_set_si(v
, 6);
256 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
257 bset
= isl_basic_set_add_constraint(bset
, c
);
259 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
260 isl_int_set_si(v
, 1);
261 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
262 isl_int_set_si(v
, -3);
263 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
264 bset
= isl_basic_set_add_constraint(bset
, c
);
266 assert(bset
->n_div
== 1);
267 isl_basic_set_free(bset
);
270 /* This test is a bit tricky. We set up an equality
272 * Normalization of divs creates _two_ divs
275 * Afterwards e0 is removed again because it has coefficient -1
276 * and we end up with the original equality and div again.
277 * Perhaps we can avoid the introduction of this temporary div.
279 dim
= isl_dim_set_alloc(ctx
, 0, 3);
280 bset
= isl_basic_set_universe(dim
);
282 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
283 isl_int_set_si(v
, -1);
284 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
285 isl_int_set_si(v
, -3);
286 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
287 isl_int_set_si(v
, -3);
288 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
289 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
290 c
= isl_constraint_add_div(c
, div
, &pos
);
291 isl_int_set_si(v
, 6);
292 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
293 bset
= isl_basic_set_add_constraint(bset
, c
);
295 /* Test disabled for now */
297 assert(bset->n_div == 1);
299 isl_basic_set_free(bset
);
302 dim
= isl_dim_set_alloc(ctx
, 0, 4);
303 bset
= isl_basic_set_universe(dim
);
305 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
306 isl_int_set_si(v
, -1);
307 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
308 isl_int_set_si(v
, -3);
309 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
310 isl_int_set_si(v
, -3);
311 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
312 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
313 c
= isl_constraint_add_div(c
, div
, &pos
);
314 isl_int_set_si(v
, 6);
315 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
316 bset
= isl_basic_set_add_constraint(bset
, c
);
318 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
319 isl_int_set_si(v
, -1);
320 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
321 isl_int_set_si(v
, 1);
322 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
323 isl_int_set_si(v
, 1);
324 isl_constraint_set_constant(c
, v
);
325 bset
= isl_basic_set_add_constraint(bset
, c
);
327 /* Test disabled for now */
329 assert(bset->n_div == 1);
331 isl_basic_set_free(bset
);
334 dim
= isl_dim_set_alloc(ctx
, 0, 2);
335 bset
= isl_basic_set_universe(dim
);
337 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
338 isl_int_set_si(v
, 1);
339 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
340 isl_int_set_si(v
, -1);
341 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
342 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
343 c
= isl_constraint_add_div(c
, div
, &pos
);
344 isl_int_set_si(v
, -2);
345 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
346 bset
= isl_basic_set_add_constraint(bset
, c
);
348 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
349 isl_int_set_si(v
, -1);
350 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
351 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
352 c
= isl_constraint_add_div(c
, div
, &pos
);
353 isl_int_set_si(v
, 3);
354 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
355 isl_int_set_si(v
, 2);
356 isl_constraint_set_constant(c
, v
);
357 bset
= isl_basic_set_add_constraint(bset
, c
);
359 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
361 assert(!isl_basic_set_is_empty(bset
));
363 isl_basic_set_free(bset
);
366 dim
= isl_dim_set_alloc(ctx
, 0, 2);
367 bset
= isl_basic_set_universe(dim
);
369 c
= isl_equality_alloc(isl_dim_copy(bset
->dim
));
370 isl_int_set_si(v
, 1);
371 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
372 div
= isl_div_alloc(isl_dim_copy(bset
->dim
));
373 c
= isl_constraint_add_div(c
, div
, &pos
);
374 isl_int_set_si(v
, -2);
375 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
376 bset
= isl_basic_set_add_constraint(bset
, c
);
378 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
380 isl_basic_set_free(bset
);
385 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
387 char filename
[PATH_MAX
];
390 struct isl_basic_set
*bset1
, *bset2
;
391 struct isl_basic_map
*bmap
;
393 n
= snprintf(filename
, sizeof(filename
),
394 "%s/test_inputs/%s.omega", srcdir
, name
);
395 assert(n
< sizeof(filename
));
396 input
= fopen(filename
, "r");
399 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
400 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
402 bset1
= isl_basic_set_apply(bset1
, bmap
);
404 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
406 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
408 isl_basic_set_free(bset1
);
409 isl_basic_set_free(bset2
);
414 void test_application(struct isl_ctx
*ctx
)
416 test_application_case(ctx
, "application");
417 test_application_case(ctx
, "application2");
420 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
422 char filename
[PATH_MAX
];
425 struct isl_basic_set
*bset1
, *bset2
;
427 n
= snprintf(filename
, sizeof(filename
),
428 "%s/test_inputs/%s.polylib", srcdir
, name
);
429 assert(n
< sizeof(filename
));
430 input
= fopen(filename
, "r");
433 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
434 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
436 bset1
= isl_basic_set_affine_hull(bset1
);
438 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
440 isl_basic_set_free(bset1
);
441 isl_basic_set_free(bset2
);
446 void test_affine_hull(struct isl_ctx
*ctx
)
448 test_affine_hull_case(ctx
, "affine2");
449 test_affine_hull_case(ctx
, "affine");
450 test_affine_hull_case(ctx
, "affine3");
453 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
455 char filename
[PATH_MAX
];
458 struct isl_basic_set
*bset1
, *bset2
;
461 n
= snprintf(filename
, sizeof(filename
),
462 "%s/test_inputs/%s.polylib", srcdir
, name
);
463 assert(n
< sizeof(filename
));
464 input
= fopen(filename
, "r");
467 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
468 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
470 set
= isl_basic_set_union(bset1
, bset2
);
471 bset1
= isl_set_convex_hull(set
);
473 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
475 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
477 isl_basic_set_free(bset1
);
478 isl_basic_set_free(bset2
);
483 void test_convex_hull(struct isl_ctx
*ctx
)
485 test_convex_hull_case(ctx
, "convex0");
486 test_convex_hull_case(ctx
, "convex1");
487 test_convex_hull_case(ctx
, "convex2");
488 test_convex_hull_case(ctx
, "convex3");
489 test_convex_hull_case(ctx
, "convex4");
490 test_convex_hull_case(ctx
, "convex5");
491 test_convex_hull_case(ctx
, "convex6");
492 test_convex_hull_case(ctx
, "convex7");
493 test_convex_hull_case(ctx
, "convex8");
494 test_convex_hull_case(ctx
, "convex9");
495 test_convex_hull_case(ctx
, "convex10");
496 test_convex_hull_case(ctx
, "convex11");
497 test_convex_hull_case(ctx
, "convex12");
498 test_convex_hull_case(ctx
, "convex13");
499 test_convex_hull_case(ctx
, "convex14");
500 test_convex_hull_case(ctx
, "convex15");
503 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
505 char filename
[PATH_MAX
];
508 struct isl_basic_set
*bset1
, *bset2
;
510 n
= snprintf(filename
, sizeof(filename
),
511 "%s/test_inputs/%s.polylib", srcdir
, name
);
512 assert(n
< sizeof(filename
));
513 input
= fopen(filename
, "r");
516 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
517 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
519 bset1
= isl_basic_set_gist(bset1
, bset2
);
521 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
523 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
525 isl_basic_set_free(bset1
);
526 isl_basic_set_free(bset2
);
531 void test_gist(struct isl_ctx
*ctx
)
533 test_gist_case(ctx
, "gist1");
536 void test_coalesce(struct isl_ctx
*ctx
)
539 struct isl_set
*set
, *set2
;
540 struct isl_map
*map
, *map2
;
542 set
= isl_set_read_from_str(ctx
,
543 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
544 "y >= x & x >= 2 & 5 >= y }", -1);
545 set
= isl_set_coalesce(set
);
546 assert(set
&& set
->n
== 1);
549 set
= isl_set_read_from_str(ctx
,
550 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
551 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
552 set
= isl_set_coalesce(set
);
553 assert(set
&& set
->n
== 1);
556 set
= isl_set_read_from_str(ctx
,
557 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
558 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
559 set
= isl_set_coalesce(set
);
560 assert(set
&& set
->n
== 2);
563 set
= isl_set_read_from_str(ctx
,
564 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
565 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
566 set
= isl_set_coalesce(set
);
567 assert(set
&& set
->n
== 1);
570 set
= isl_set_read_from_str(ctx
,
571 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
572 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
573 set
= isl_set_coalesce(set
);
574 assert(set
&& set
->n
== 2);
577 set
= isl_set_read_from_str(ctx
,
578 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
579 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
580 set
= isl_set_coalesce(set
);
581 assert(set
&& set
->n
== 2);
584 set
= isl_set_read_from_str(ctx
,
585 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
586 "y >= 0 & x = 6 & y <= 6}", -1);
587 set
= isl_set_coalesce(set
);
588 assert(set
&& set
->n
== 1);
591 set
= isl_set_read_from_str(ctx
,
592 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
593 "y >= 0 & x = 7 & y <= 6}", -1);
594 set
= isl_set_coalesce(set
);
595 assert(set
&& set
->n
== 2);
598 set
= isl_set_read_from_str(ctx
,
599 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
600 "y >= 0 & x = 6 & y <= 5}", -1);
601 set
= isl_set_coalesce(set
);
602 assert(set
&& set
->n
== 1);
603 set2
= isl_set_read_from_str(ctx
,
604 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
605 "y >= 0 & x = 6 & y <= 5}", -1);
606 assert(isl_set_is_equal(set
, set2
));
610 set
= isl_set_read_from_str(ctx
,
611 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
612 "y >= 0 & x = 6 & y <= 7}", -1);
613 set
= isl_set_coalesce(set
);
614 assert(set
&& set
->n
== 2);
617 set
= isl_set_read_from_str(ctx
,
618 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
619 set
= isl_set_coalesce(set
);
620 assert(set
&& set
->n
== 1);
621 set2
= isl_set_read_from_str(ctx
,
622 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
623 assert(isl_set_is_equal(set
, set2
));
627 set
= isl_set_read_from_str(ctx
,
628 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
629 set
= isl_set_coalesce(set
);
630 set2
= isl_set_read_from_str(ctx
,
631 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
632 assert(isl_set_is_equal(set
, set2
));
636 set
= isl_set_read_from_str(ctx
,
637 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
638 "2 <= i and i <= n }", -1);
639 set
= isl_set_coalesce(set
);
640 assert(set
&& set
->n
== 1);
641 set2
= isl_set_read_from_str(ctx
,
642 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
643 "2 <= i and i <= n }", -1);
644 assert(isl_set_is_equal(set
, set2
));
648 map
= isl_map_read_from_str(ctx
,
649 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
650 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
651 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
652 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
653 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
654 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
655 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
656 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
657 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
658 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
659 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
660 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
661 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
662 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
663 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
664 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
665 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
666 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
667 map
= isl_map_coalesce(map
);
668 map2
= isl_map_read_from_str(ctx
,
669 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
670 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
671 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
672 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
673 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
674 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
675 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
676 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
677 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
678 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
679 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
680 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
681 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
682 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
683 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
684 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
685 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
686 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
687 assert(isl_map_is_equal(map
, map2
));
691 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
692 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
693 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
694 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
695 map
= isl_map_read_from_str(ctx
, str
, -1);
696 map
= isl_map_coalesce(map
);
697 map2
= isl_map_read_from_str(ctx
, str
, -1);
698 assert(isl_map_is_equal(map
, map2
));
702 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
703 "[o0, o1, o2, o3, o4, o5, o6] : "
704 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
705 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
706 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
707 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
708 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
709 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
710 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
711 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
712 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
713 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
714 "o6 >= i3 + i6 - o3 and M >= 0 and "
715 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
716 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
717 map
= isl_map_read_from_str(ctx
, str
, -1);
718 map
= isl_map_coalesce(map
);
719 map2
= isl_map_read_from_str(ctx
, str
, -1);
720 assert(isl_map_is_equal(map
, map2
));
724 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
725 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
726 "(o0 = 0 and M >= 2 and N >= 3) or "
727 "(M = 0 and o0 = 0 and N >= 3) }";
728 map
= isl_map_read_from_str(ctx
, str
, -1);
729 map
= isl_map_coalesce(map
);
730 map2
= isl_map_read_from_str(ctx
, str
, -1);
731 assert(isl_map_is_equal(map
, map2
));
736 void test_closure(struct isl_ctx
*ctx
)
744 /* COCOA example 1 */
745 map
= isl_map_read_from_str(ctx
,
746 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
747 "1 <= i and i < n and 1 <= j and j < n or "
748 "i2 = i + 1 and j2 = j - 1 and "
749 "1 <= i and i < n and 2 <= j and j <= n }", -1);
750 map
= isl_map_power(map
, 1, &exact
);
754 /* COCOA example 1 */
755 map
= isl_map_read_from_str(ctx
,
756 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
757 "1 <= i and i < n and 1 <= j and j < n or "
758 "i2 = i + 1 and j2 = j - 1 and "
759 "1 <= i and i < n and 2 <= j and j <= n }", -1);
760 map
= isl_map_transitive_closure(map
, &exact
);
762 map2
= isl_map_read_from_str(ctx
,
763 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
764 "1 <= i and i < n and 1 <= j and j <= n and "
765 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
766 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
767 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
768 assert(isl_map_is_equal(map
, map2
));
772 map
= isl_map_read_from_str(ctx
,
773 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
774 " 0 <= y and y <= n }", -1);
775 map
= isl_map_transitive_closure(map
, &exact
);
776 map2
= isl_map_read_from_str(ctx
,
777 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
778 " 0 <= y and y <= n }", -1);
779 assert(isl_map_is_equal(map
, map2
));
783 /* COCOA example 2 */
784 map
= isl_map_read_from_str(ctx
,
785 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
786 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
787 "i2 = i + 2 and j2 = j - 2 and "
788 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
789 map
= isl_map_transitive_closure(map
, &exact
);
791 map2
= isl_map_read_from_str(ctx
,
792 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
793 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
794 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
795 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
796 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
797 assert(isl_map_is_equal(map
, map2
));
801 /* COCOA Fig.2 left */
802 map
= isl_map_read_from_str(ctx
,
803 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
804 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
806 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
807 "j <= 2 i - 3 and j <= n - 2 or "
808 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
809 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
810 map
= isl_map_transitive_closure(map
, &exact
);
814 /* COCOA Fig.2 right */
815 map
= isl_map_read_from_str(ctx
,
816 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
817 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
819 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
820 "j <= 2 i - 4 and j <= n - 3 or "
821 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
822 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
823 map
= isl_map_power(map
, 1, &exact
);
827 /* COCOA Fig.2 right */
828 map
= isl_map_read_from_str(ctx
,
829 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
830 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
832 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
833 "j <= 2 i - 4 and j <= n - 3 or "
834 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
835 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
836 map
= isl_map_transitive_closure(map
, &exact
);
838 map2
= isl_map_read_from_str(ctx
,
839 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
840 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
841 "j <= n and 3 + i + 2 j <= 3 n and "
842 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
843 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
844 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
845 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
846 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
847 assert(isl_map_is_equal(map
, map2
));
851 /* COCOA Fig.1 right */
852 dom
= isl_set_read_from_str(ctx
,
853 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
854 "2 x - 3 y + 3 >= 0 }", -1);
855 right
= isl_map_read_from_str(ctx
,
856 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
857 up
= isl_map_read_from_str(ctx
,
858 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
859 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
860 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
861 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
862 up
= isl_map_intersect_range(up
, dom
);
863 map
= isl_map_union(up
, right
);
864 map
= isl_map_transitive_closure(map
, &exact
);
868 /* COCOA Theorem 1 counter example */
869 map
= isl_map_read_from_str(ctx
,
870 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
871 "i2 = 1 and j2 = j or "
872 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
873 map
= isl_map_transitive_closure(map
, &exact
);
877 map
= isl_map_read_from_str(ctx
,
878 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
879 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
880 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
881 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
882 map
= isl_map_transitive_closure(map
, &exact
);
886 /* Kelly et al 1996, fig 12 */
887 map
= isl_map_read_from_str(ctx
,
888 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
889 "1 <= i,j,j+1 <= n or "
890 "j = n and j2 = 1 and i2 = i + 1 and "
891 "1 <= i,i+1 <= n }", -1);
892 map
= isl_map_transitive_closure(map
, &exact
);
894 map2
= isl_map_read_from_str(ctx
,
895 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
896 "1 <= i <= n and i = i2 or "
897 "1 <= i < i2 <= n and 1 <= j <= n and "
898 "1 <= j2 <= n }", -1);
899 assert(isl_map_is_equal(map
, map2
));
903 /* Omega's closure4 */
904 map
= isl_map_read_from_str(ctx
,
905 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
907 "x2 = x + 1 and y2 = y and "
908 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
909 map
= isl_map_transitive_closure(map
, &exact
);
913 map
= isl_map_read_from_str(ctx
,
914 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
915 map
= isl_map_transitive_closure(map
, &exact
);
917 map2
= isl_map_read_from_str(ctx
,
918 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
919 assert(isl_map_is_equal(map
, map2
));
923 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
924 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
925 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
926 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
927 map
= isl_map_read_from_str(ctx
, str
, -1);
928 map
= isl_map_transitive_closure(map
, &exact
);
930 map2
= isl_map_read_from_str(ctx
, str
, -1);
931 assert(isl_map_is_equal(map
, map2
));
940 srcdir
= getenv("srcdir");
943 ctx
= isl_ctx_alloc();
945 test_construction(ctx
);
948 test_application(ctx
);
949 test_affine_hull(ctx
);
950 test_convex_hull(ctx
);