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
13 #include <isl_map_private.h>
17 #include <isl/constraint.h>
18 #include <isl/polynomial.h>
19 #include <isl/union_map.h>
20 #include <isl_factorization.h>
24 void test_parse_map(isl_ctx
*ctx
, const char *str
)
28 map
= isl_map_read_from_str(ctx
, str
, -1);
33 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
35 isl_pw_qpolynomial
*pwqp
;
37 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
39 isl_pw_qpolynomial_free(pwqp
);
42 void test_parse(struct isl_ctx
*ctx
)
47 str
= "{ [i] -> [-i] }";
48 map
= isl_map_read_from_str(ctx
, str
, -1);
52 str
= "{ A[i] -> L[([i/3])] }";
53 map
= isl_map_read_from_str(ctx
, str
, -1);
57 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
59 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
60 map
= isl_map_read_from_str(ctx
, str
, -1);
61 str
= "{ [new, old] -> [o0, o1] : "
62 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
63 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
64 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
65 map2
= isl_map_read_from_str(ctx
, str
, -1);
66 assert(isl_map_is_equal(map
, map2
));
70 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
71 map
= isl_map_read_from_str(ctx
, str
, -1);
72 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
73 map2
= isl_map_read_from_str(ctx
, str
, -1);
74 assert(isl_map_is_equal(map
, map2
));
78 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
81 void test_read(struct isl_ctx
*ctx
)
83 char filename
[PATH_MAX
];
86 struct isl_basic_set
*bset1
, *bset2
;
87 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
89 n
= snprintf(filename
, sizeof(filename
),
90 "%s/test_inputs/set.omega", srcdir
);
91 assert(n
< sizeof(filename
));
92 input
= fopen(filename
, "r");
95 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
96 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
98 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
100 isl_basic_set_free(bset1
);
101 isl_basic_set_free(bset2
);
106 void test_bounded(struct isl_ctx
*ctx
)
111 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
112 bounded
= isl_set_is_bounded(set
);
116 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
117 bounded
= isl_set_is_bounded(set
);
121 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
122 bounded
= isl_set_is_bounded(set
);
127 /* Construct the basic set { [i] : 5 <= i <= N } */
128 void test_construction(struct isl_ctx
*ctx
)
132 struct isl_basic_set
*bset
;
133 struct isl_constraint
*c
;
137 dim
= isl_dim_set_alloc(ctx
, 1, 1);
138 bset
= isl_basic_set_universe(dim
);
140 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
141 isl_int_set_si(v
, -1);
142 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
143 isl_int_set_si(v
, 1);
144 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
145 bset
= isl_basic_set_add_constraint(bset
, c
);
147 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
148 isl_int_set_si(v
, 1);
149 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
150 isl_int_set_si(v
, -5);
151 isl_constraint_set_constant(c
, v
);
152 bset
= isl_basic_set_add_constraint(bset
, c
);
154 isl_basic_set_free(bset
);
159 void test_dim(struct isl_ctx
*ctx
)
162 isl_map
*map1
, *map2
;
164 map1
= isl_map_read_from_str(ctx
,
165 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
166 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
167 map2
= isl_map_read_from_str(ctx
,
168 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
169 assert(isl_map_is_equal(map1
, map2
));
172 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
173 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
174 assert(isl_map_is_equal(map1
, map2
));
179 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
180 map1
= isl_map_read_from_str(ctx
, str
, -1);
181 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
182 map2
= isl_map_read_from_str(ctx
, str
, -1);
183 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
184 assert(isl_map_is_equal(map1
, map2
));
190 void test_div(struct isl_ctx
*ctx
)
196 struct isl_basic_set
*bset
;
197 struct isl_constraint
*c
;
202 dim
= isl_dim_set_alloc(ctx
, 0, 1);
203 bset
= isl_basic_set_universe(dim
);
205 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
206 isl_int_set_si(v
, -1);
207 isl_constraint_set_constant(c
, v
);
208 isl_int_set_si(v
, 1);
209 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
210 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
211 c
= isl_constraint_add_div(c
, div
, &pos
);
212 isl_int_set_si(v
, 3);
213 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
214 bset
= isl_basic_set_add_constraint(bset
, c
);
216 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
217 isl_int_set_si(v
, 1);
218 isl_constraint_set_constant(c
, v
);
219 isl_int_set_si(v
, -1);
220 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
221 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
222 c
= isl_constraint_add_div(c
, div
, &pos
);
223 isl_int_set_si(v
, 3);
224 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
225 bset
= isl_basic_set_add_constraint(bset
, c
);
227 assert(bset
&& bset
->n_div
== 1);
228 isl_basic_set_free(bset
);
231 dim
= isl_dim_set_alloc(ctx
, 0, 1);
232 bset
= isl_basic_set_universe(dim
);
234 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
235 isl_int_set_si(v
, 1);
236 isl_constraint_set_constant(c
, v
);
237 isl_int_set_si(v
, -1);
238 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
239 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
240 c
= isl_constraint_add_div(c
, div
, &pos
);
241 isl_int_set_si(v
, 3);
242 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
243 bset
= isl_basic_set_add_constraint(bset
, c
);
245 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
246 isl_int_set_si(v
, -1);
247 isl_constraint_set_constant(c
, v
);
248 isl_int_set_si(v
, 1);
249 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
250 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
251 c
= isl_constraint_add_div(c
, div
, &pos
);
252 isl_int_set_si(v
, 3);
253 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
254 bset
= isl_basic_set_add_constraint(bset
, c
);
256 assert(bset
&& bset
->n_div
== 1);
257 isl_basic_set_free(bset
);
260 dim
= isl_dim_set_alloc(ctx
, 0, 1);
261 bset
= isl_basic_set_universe(dim
);
263 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
264 isl_int_set_si(v
, 1);
265 isl_constraint_set_constant(c
, v
);
266 isl_int_set_si(v
, -1);
267 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
268 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
269 c
= isl_constraint_add_div(c
, div
, &pos
);
270 isl_int_set_si(v
, 3);
271 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
272 bset
= isl_basic_set_add_constraint(bset
, c
);
274 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
275 isl_int_set_si(v
, -3);
276 isl_constraint_set_constant(c
, v
);
277 isl_int_set_si(v
, 1);
278 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
279 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
280 c
= isl_constraint_add_div(c
, div
, &pos
);
281 isl_int_set_si(v
, 4);
282 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
283 bset
= isl_basic_set_add_constraint(bset
, c
);
285 assert(bset
&& bset
->n_div
== 1);
286 isl_basic_set_free(bset
);
289 dim
= isl_dim_set_alloc(ctx
, 0, 1);
290 bset
= isl_basic_set_universe(dim
);
292 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
293 isl_int_set_si(v
, 2);
294 isl_constraint_set_constant(c
, v
);
295 isl_int_set_si(v
, -1);
296 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
297 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
298 c
= isl_constraint_add_div(c
, div
, &pos
);
299 isl_int_set_si(v
, 3);
300 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
301 bset
= isl_basic_set_add_constraint(bset
, c
);
303 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
304 isl_int_set_si(v
, -1);
305 isl_constraint_set_constant(c
, v
);
306 isl_int_set_si(v
, 1);
307 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
308 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
309 c
= isl_constraint_add_div(c
, div
, &pos
);
310 isl_int_set_si(v
, 6);
311 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
312 bset
= isl_basic_set_add_constraint(bset
, c
);
314 assert(isl_basic_set_is_empty(bset
));
315 isl_basic_set_free(bset
);
318 dim
= isl_dim_set_alloc(ctx
, 0, 2);
319 bset
= isl_basic_set_universe(dim
);
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 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
325 c
= isl_constraint_add_div(c
, div
, &pos
);
326 isl_int_set_si(v
, 3);
327 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
328 bset
= isl_basic_set_add_constraint(bset
, c
);
330 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
331 isl_int_set_si(v
, 1);
332 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
333 isl_int_set_si(v
, -3);
334 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
335 bset
= isl_basic_set_add_constraint(bset
, c
);
337 assert(bset
&& bset
->n_div
== 0);
338 isl_basic_set_free(bset
);
341 dim
= isl_dim_set_alloc(ctx
, 0, 2);
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 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
348 c
= isl_constraint_add_div(c
, div
, &pos
);
349 isl_int_set_si(v
, 6);
350 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
351 bset
= isl_basic_set_add_constraint(bset
, c
);
353 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
354 isl_int_set_si(v
, 1);
355 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
356 isl_int_set_si(v
, -3);
357 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
358 bset
= isl_basic_set_add_constraint(bset
, c
);
360 assert(bset
&& bset
->n_div
== 1);
361 isl_basic_set_free(bset
);
364 /* This test is a bit tricky. We set up an equality
366 * Normalization of divs creates _two_ divs
369 * Afterwards e0 is removed again because it has coefficient -1
370 * and we end up with the original equality and div again.
371 * Perhaps we can avoid the introduction of this temporary div.
373 dim
= isl_dim_set_alloc(ctx
, 0, 3);
374 bset
= isl_basic_set_universe(dim
);
376 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
377 isl_int_set_si(v
, -1);
378 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
379 isl_int_set_si(v
, -3);
380 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
381 isl_int_set_si(v
, -3);
382 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
383 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
384 c
= isl_constraint_add_div(c
, div
, &pos
);
385 isl_int_set_si(v
, 6);
386 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, 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, 4);
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
, -3);
403 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
404 isl_int_set_si(v
, -3);
405 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
406 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
407 c
= isl_constraint_add_div(c
, div
, &pos
);
408 isl_int_set_si(v
, 6);
409 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
410 bset
= isl_basic_set_add_constraint(bset
, c
);
412 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
413 isl_int_set_si(v
, -1);
414 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
415 isl_int_set_si(v
, 1);
416 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
417 isl_int_set_si(v
, 1);
418 isl_constraint_set_constant(c
, v
);
419 bset
= isl_basic_set_add_constraint(bset
, c
);
421 /* Test disabled for now */
423 assert(bset && bset->n_div == 1);
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 isl_int_set_si(v
, -1);
435 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
436 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
437 c
= isl_constraint_add_div(c
, div
, &pos
);
438 isl_int_set_si(v
, -2);
439 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
440 bset
= isl_basic_set_add_constraint(bset
, c
);
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
, 3);
448 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
449 isl_int_set_si(v
, 2);
450 isl_constraint_set_constant(c
, v
);
451 bset
= isl_basic_set_add_constraint(bset
, c
);
453 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
455 assert(!isl_basic_set_is_empty(bset
));
457 isl_basic_set_free(bset
);
460 dim
= isl_dim_set_alloc(ctx
, 0, 2);
461 bset
= isl_basic_set_universe(dim
);
463 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
464 isl_int_set_si(v
, 1);
465 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
466 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
467 c
= isl_constraint_add_div(c
, div
, &pos
);
468 isl_int_set_si(v
, -2);
469 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
470 bset
= isl_basic_set_add_constraint(bset
, c
);
472 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
474 isl_basic_set_free(bset
);
479 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
481 char filename
[PATH_MAX
];
484 struct isl_basic_set
*bset1
, *bset2
;
485 struct isl_basic_map
*bmap
;
487 n
= snprintf(filename
, sizeof(filename
),
488 "%s/test_inputs/%s.omega", srcdir
, name
);
489 assert(n
< sizeof(filename
));
490 input
= fopen(filename
, "r");
493 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
494 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
496 bset1
= isl_basic_set_apply(bset1
, bmap
);
498 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
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_application(struct isl_ctx
*ctx
)
510 test_application_case(ctx
, "application");
511 test_application_case(ctx
, "application2");
514 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
516 char filename
[PATH_MAX
];
519 struct isl_basic_set
*bset1
, *bset2
;
521 n
= snprintf(filename
, sizeof(filename
),
522 "%s/test_inputs/%s.polylib", srcdir
, name
);
523 assert(n
< sizeof(filename
));
524 input
= fopen(filename
, "r");
527 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
528 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
530 bset1
= isl_basic_set_affine_hull(bset1
);
532 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
534 isl_basic_set_free(bset1
);
535 isl_basic_set_free(bset2
);
540 void test_affine_hull(struct isl_ctx
*ctx
)
542 test_affine_hull_case(ctx
, "affine2");
543 test_affine_hull_case(ctx
, "affine");
544 test_affine_hull_case(ctx
, "affine3");
547 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
549 char filename
[PATH_MAX
];
552 struct isl_basic_set
*bset1
, *bset2
;
555 n
= snprintf(filename
, sizeof(filename
),
556 "%s/test_inputs/%s.polylib", srcdir
, name
);
557 assert(n
< sizeof(filename
));
558 input
= fopen(filename
, "r");
561 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
562 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
564 set
= isl_basic_set_union(bset1
, bset2
);
565 bset1
= isl_set_convex_hull(set
);
567 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
569 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
571 isl_basic_set_free(bset1
);
572 isl_basic_set_free(bset2
);
577 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
579 const char *str1
, *str2
;
580 isl_set
*set1
, *set2
;
581 int orig_convex
= ctx
->opt
->convex
;
582 ctx
->opt
->convex
= convex
;
584 test_convex_hull_case(ctx
, "convex0");
585 test_convex_hull_case(ctx
, "convex1");
586 test_convex_hull_case(ctx
, "convex2");
587 test_convex_hull_case(ctx
, "convex3");
588 test_convex_hull_case(ctx
, "convex4");
589 test_convex_hull_case(ctx
, "convex5");
590 test_convex_hull_case(ctx
, "convex6");
591 test_convex_hull_case(ctx
, "convex7");
592 test_convex_hull_case(ctx
, "convex8");
593 test_convex_hull_case(ctx
, "convex9");
594 test_convex_hull_case(ctx
, "convex10");
595 test_convex_hull_case(ctx
, "convex11");
596 test_convex_hull_case(ctx
, "convex12");
597 test_convex_hull_case(ctx
, "convex13");
598 test_convex_hull_case(ctx
, "convex14");
599 test_convex_hull_case(ctx
, "convex15");
601 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
602 "(i0 = 1 and i1 = 0 and i2 = 1) or "
603 "(i0 = 0 and i1 = 0 and i2 = 0) }";
604 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
605 set1
= isl_set_read_from_str(ctx
, str1
, -1);
606 set2
= isl_set_read_from_str(ctx
, str2
, -1);
607 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
608 assert(isl_set_is_equal(set1
, set2
));
612 ctx
->opt
->convex
= orig_convex
;
615 void test_convex_hull(struct isl_ctx
*ctx
)
617 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
618 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
621 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
623 char filename
[PATH_MAX
];
626 struct isl_basic_set
*bset1
, *bset2
;
628 n
= snprintf(filename
, sizeof(filename
),
629 "%s/test_inputs/%s.polylib", srcdir
, name
);
630 assert(n
< sizeof(filename
));
631 input
= fopen(filename
, "r");
634 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
635 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
637 bset1
= isl_basic_set_gist(bset1
, bset2
);
639 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
641 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
643 isl_basic_set_free(bset1
);
644 isl_basic_set_free(bset2
);
649 void test_gist(struct isl_ctx
*ctx
)
651 test_gist_case(ctx
, "gist1");
654 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
658 set
= isl_set_read_from_str(ctx
, str
, -1);
659 set
= isl_set_coalesce(set
);
660 set2
= isl_set_read_from_str(ctx
, str
, -1);
661 assert(isl_set_is_equal(set
, set2
));
663 assert(set
&& set
->n
== 1);
668 void test_coalesce(struct isl_ctx
*ctx
)
671 struct isl_set
*set
, *set2
;
672 struct isl_map
*map
, *map2
;
674 set
= isl_set_read_from_str(ctx
,
675 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
676 "y >= x & x >= 2 & 5 >= y }", -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 & 2x + y <= 30 & y <= 10 & x >= 0 or "
683 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
684 set
= isl_set_coalesce(set
);
685 assert(set
&& set
->n
== 1);
688 set
= isl_set_read_from_str(ctx
,
689 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
690 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
691 set
= isl_set_coalesce(set
);
692 assert(set
&& set
->n
== 2);
695 set
= isl_set_read_from_str(ctx
,
696 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
697 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
698 set
= isl_set_coalesce(set
);
699 assert(set
&& set
->n
== 1);
702 set
= isl_set_read_from_str(ctx
,
703 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
704 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
705 set
= isl_set_coalesce(set
);
706 assert(set
&& set
->n
== 2);
709 set
= isl_set_read_from_str(ctx
,
710 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
711 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
712 set
= isl_set_coalesce(set
);
713 assert(set
&& set
->n
== 2);
716 set
= isl_set_read_from_str(ctx
,
717 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
718 "y >= 0 & x = 6 & y <= 6}", -1);
719 set
= isl_set_coalesce(set
);
720 assert(set
&& set
->n
== 1);
723 set
= isl_set_read_from_str(ctx
,
724 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
725 "y >= 0 & x = 7 & y <= 6}", -1);
726 set
= isl_set_coalesce(set
);
727 assert(set
&& set
->n
== 2);
730 set
= isl_set_read_from_str(ctx
,
731 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
732 "y >= 0 & x = 6 & y <= 5}", -1);
733 set
= isl_set_coalesce(set
);
734 assert(set
&& set
->n
== 1);
735 set2
= isl_set_read_from_str(ctx
,
736 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
737 "y >= 0 & x = 6 & y <= 5}", -1);
738 assert(isl_set_is_equal(set
, set2
));
742 set
= isl_set_read_from_str(ctx
,
743 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
744 "y >= 0 & x = 6 & y <= 7}", -1);
745 set
= isl_set_coalesce(set
);
746 assert(set
&& set
->n
== 2);
749 set
= isl_set_read_from_str(ctx
,
750 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
751 set
= isl_set_coalesce(set
);
752 assert(set
&& set
->n
== 1);
753 set2
= isl_set_read_from_str(ctx
,
754 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
755 assert(isl_set_is_equal(set
, set2
));
759 set
= isl_set_read_from_str(ctx
,
760 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
761 set
= isl_set_coalesce(set
);
762 set2
= isl_set_read_from_str(ctx
,
763 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
764 assert(isl_set_is_equal(set
, set2
));
768 set
= isl_set_read_from_str(ctx
,
769 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
770 "2 <= i and i <= n }", -1);
771 set
= isl_set_coalesce(set
);
772 assert(set
&& set
->n
== 1);
773 set2
= isl_set_read_from_str(ctx
,
774 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
775 "2 <= i and i <= n }", -1);
776 assert(isl_set_is_equal(set
, set2
));
780 map
= isl_map_read_from_str(ctx
,
781 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
782 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
783 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
784 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
785 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
786 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
787 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
788 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
789 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
790 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
791 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
792 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
793 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
794 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
795 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
796 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
797 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
798 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
799 map
= isl_map_coalesce(map
);
800 map2
= isl_map_read_from_str(ctx
,
801 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
802 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
803 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
804 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
805 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
806 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
807 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
808 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
809 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
810 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
811 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
812 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
813 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
814 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
815 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
816 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
817 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
818 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
819 assert(isl_map_is_equal(map
, map2
));
823 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
824 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
825 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
826 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
827 map
= isl_map_read_from_str(ctx
, str
, -1);
828 map
= isl_map_coalesce(map
);
829 map2
= isl_map_read_from_str(ctx
, str
, -1);
830 assert(isl_map_is_equal(map
, map2
));
834 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
835 "[o0, o1, o2, o3, o4, o5, o6] : "
836 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
837 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
838 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
839 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
840 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
841 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
842 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
843 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
844 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
845 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
846 "o6 >= i3 + i6 - o3 and M >= 0 and "
847 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
848 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
849 map
= isl_map_read_from_str(ctx
, str
, -1);
850 map
= isl_map_coalesce(map
);
851 map2
= isl_map_read_from_str(ctx
, str
, -1);
852 assert(isl_map_is_equal(map
, map2
));
856 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
857 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
858 "(o0 = 0 and M >= 2 and N >= 3) or "
859 "(M = 0 and o0 = 0 and N >= 3) }";
860 map
= isl_map_read_from_str(ctx
, str
, -1);
861 map
= isl_map_coalesce(map
);
862 map2
= isl_map_read_from_str(ctx
, str
, -1);
863 assert(isl_map_is_equal(map
, map2
));
867 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
868 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
869 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
870 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
871 map
= isl_map_read_from_str(ctx
, str
, -1);
872 map
= isl_map_coalesce(map
);
873 map2
= isl_map_read_from_str(ctx
, str
, -1);
874 assert(isl_map_is_equal(map
, map2
));
878 test_coalesce_set(ctx
,
879 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
880 "(i1 = M and M >= 1) }", 0);
881 test_coalesce_set(ctx
,
882 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
883 test_coalesce_set(ctx
,
884 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
885 "(y = 3 and x = 1) }", 1);
886 test_coalesce_set(ctx
,
887 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
888 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
889 "i1 <= M and i3 <= M and i4 <= M) or "
890 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
891 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
892 "i4 <= -1 + M) }", 1);
893 test_coalesce_set(ctx
,
894 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
895 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
896 test_coalesce_set(ctx
,
897 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
898 "-x - y + 1 >= 0 and -3 <= z <= 3;"
899 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
900 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
901 test_coalesce_set(ctx
,
902 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
903 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
904 test_coalesce_set(ctx
,
905 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
906 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
909 void test_closure(struct isl_ctx
*ctx
)
917 /* COCOA example 1 */
918 map
= isl_map_read_from_str(ctx
,
919 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
920 "1 <= i and i < n and 1 <= j and j < n or "
921 "i2 = i + 1 and j2 = j - 1 and "
922 "1 <= i and i < n and 2 <= j and j <= n }", -1);
923 map
= isl_map_power(map
, 1, &exact
);
927 /* COCOA example 1 */
928 map
= isl_map_read_from_str(ctx
,
929 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
930 "1 <= i and i < n and 1 <= j and j < n or "
931 "i2 = i + 1 and j2 = j - 1 and "
932 "1 <= i and i < n and 2 <= j and j <= n }", -1);
933 map
= isl_map_transitive_closure(map
, &exact
);
935 map2
= isl_map_read_from_str(ctx
,
936 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
937 "1 <= i and i < n and 1 <= j and j <= n and "
938 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
939 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
940 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
941 assert(isl_map_is_equal(map
, map2
));
945 map
= isl_map_read_from_str(ctx
,
946 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
947 " 0 <= y and y <= n }", -1);
948 map
= isl_map_transitive_closure(map
, &exact
);
949 map2
= isl_map_read_from_str(ctx
,
950 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
951 " 0 <= y and y <= n }", -1);
952 assert(isl_map_is_equal(map
, map2
));
956 /* COCOA example 2 */
957 map
= isl_map_read_from_str(ctx
,
958 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
959 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
960 "i2 = i + 2 and j2 = j - 2 and "
961 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
962 map
= isl_map_transitive_closure(map
, &exact
);
964 map2
= isl_map_read_from_str(ctx
,
965 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
966 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
967 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
968 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
969 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
970 assert(isl_map_is_equal(map
, map2
));
974 /* COCOA Fig.2 left */
975 map
= isl_map_read_from_str(ctx
,
976 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
977 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
979 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
980 "j <= 2 i - 3 and j <= n - 2 or "
981 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
982 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
983 map
= isl_map_transitive_closure(map
, &exact
);
987 /* COCOA Fig.2 right */
988 map
= isl_map_read_from_str(ctx
,
989 "[n,k] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
990 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
992 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
993 "j <= 2 i - 4 and j <= n - 3 or "
994 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
995 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
996 map
= isl_map_power(map
, 1, &exact
);
1000 /* COCOA Fig.2 right */
1001 map
= isl_map_read_from_str(ctx
,
1002 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1003 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1005 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1006 "j <= 2 i - 4 and j <= n - 3 or "
1007 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1008 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1009 map
= isl_map_transitive_closure(map
, &exact
);
1011 map2
= isl_map_read_from_str(ctx
,
1012 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1013 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1014 "j <= n and 3 + i + 2 j <= 3 n and "
1015 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1016 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1017 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1018 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1019 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1020 assert(isl_map_is_equal(map
, map2
));
1024 /* COCOA Fig.1 right */
1025 dom
= isl_set_read_from_str(ctx
,
1026 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1027 "2 x - 3 y + 3 >= 0 }", -1);
1028 right
= isl_map_read_from_str(ctx
,
1029 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1030 up
= isl_map_read_from_str(ctx
,
1031 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1032 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1033 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1034 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1035 up
= isl_map_intersect_range(up
, dom
);
1036 map
= isl_map_union(up
, right
);
1037 map
= isl_map_transitive_closure(map
, &exact
);
1039 map2
= isl_map_read_from_str(ctx
,
1040 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1041 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1042 assert(isl_map_is_equal(map
, map2
));
1046 /* COCOA Theorem 1 counter example */
1047 map
= isl_map_read_from_str(ctx
,
1048 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1049 "i2 = 1 and j2 = j or "
1050 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1051 map
= isl_map_transitive_closure(map
, &exact
);
1055 map
= isl_map_read_from_str(ctx
,
1056 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1057 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1058 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1059 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1060 map
= isl_map_transitive_closure(map
, &exact
);
1064 /* Kelly et al 1996, fig 12 */
1065 map
= isl_map_read_from_str(ctx
,
1066 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1067 "1 <= i,j,j+1 <= n or "
1068 "j = n and j2 = 1 and i2 = i + 1 and "
1069 "1 <= i,i+1 <= n }", -1);
1070 map
= isl_map_transitive_closure(map
, &exact
);
1072 map2
= isl_map_read_from_str(ctx
,
1073 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1074 "1 <= i <= n and i = i2 or "
1075 "1 <= i < i2 <= n and 1 <= j <= n and "
1076 "1 <= j2 <= n }", -1);
1077 assert(isl_map_is_equal(map
, map2
));
1081 /* Omega's closure4 */
1082 map
= isl_map_read_from_str(ctx
,
1083 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1084 "1 <= x,y <= 10 or "
1085 "x2 = x + 1 and y2 = y and "
1086 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1087 map
= isl_map_transitive_closure(map
, &exact
);
1091 map
= isl_map_read_from_str(ctx
,
1092 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1093 map
= isl_map_transitive_closure(map
, &exact
);
1095 map2
= isl_map_read_from_str(ctx
,
1096 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1097 assert(isl_map_is_equal(map
, map2
));
1101 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1102 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1103 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1104 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1105 map
= isl_map_read_from_str(ctx
, str
, -1);
1106 map
= isl_map_transitive_closure(map
, &exact
);
1108 map2
= isl_map_read_from_str(ctx
, str
, -1);
1109 assert(isl_map_is_equal(map
, map2
));
1113 str
= "{[0] -> [1]; [2] -> [3]}";
1114 map
= isl_map_read_from_str(ctx
, str
, -1);
1115 map
= isl_map_transitive_closure(map
, &exact
);
1117 map2
= isl_map_read_from_str(ctx
, str
, -1);
1118 assert(isl_map_is_equal(map
, map2
));
1122 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1123 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1124 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1125 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1126 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1127 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1128 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1129 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1130 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1131 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1132 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1133 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1134 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1135 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1136 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1137 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1138 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1139 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1140 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1141 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1142 map
= isl_map_read_from_str(ctx
, str
, -1);
1143 map
= isl_map_transitive_closure(map
, NULL
);
1148 void test_lex(struct isl_ctx
*ctx
)
1153 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1154 map
= isl_map_lex_le(dim
);
1155 assert(!isl_map_is_empty(map
));
1159 void test_lexmin(struct isl_ctx
*ctx
)
1162 isl_map
*map
, *map2
;
1166 str
= "[p0, p1] -> { [] -> [] : "
1167 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1168 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1169 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1170 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1171 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1172 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1173 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1174 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1175 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1176 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1177 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1178 map
= isl_map_read_from_str(ctx
, str
, -1);
1179 map
= isl_map_lexmin(map
);
1182 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1183 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1184 set
= isl_set_read_from_str(ctx
, str
, -1);
1185 set
= isl_set_lexmax(set
);
1186 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1187 set2
= isl_set_read_from_str(ctx
, str
, -1);
1188 set
= isl_set_intersect(set
, set2
);
1189 assert(!isl_set_is_empty(set
));
1192 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1193 map
= isl_map_read_from_str(ctx
, str
, -1);
1194 map
= isl_map_lexmin(map
);
1195 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1196 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1197 map2
= isl_map_read_from_str(ctx
, str
, -1);
1198 assert(isl_map_is_equal(map
, map2
));
1202 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1203 map
= isl_map_read_from_str(ctx
, str
, -1);
1204 map2
= isl_map_copy(map
);
1205 map
= isl_map_lexmin(map
);
1206 assert(isl_map_is_equal(map
, map2
));
1210 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1211 map
= isl_map_read_from_str(ctx
, str
, -1);
1212 map
= isl_map_lexmin(map
);
1213 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1214 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1215 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1216 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1217 map2
= isl_map_read_from_str(ctx
, str
, -1);
1218 assert(isl_map_is_equal(map
, map2
));
1228 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1229 void *dep_user
, void *user
)
1231 struct must_may
*mm
= (struct must_may
*)user
;
1234 mm
->must
= isl_map_union(mm
->must
, dep
);
1236 mm
->may
= isl_map_union(mm
->may
, dep
);
1241 static int common_space(void *first
, void *second
)
1243 int depth
= *(int *)first
;
1247 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1255 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1256 equal
= isl_map_is_equal(map
, map2
);
1262 void test_dep(struct isl_ctx
*ctx
)
1267 isl_access_info
*ai
;
1274 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1275 map
= isl_map_read_from_str(ctx
, str
, -1);
1276 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1278 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1279 map
= isl_map_read_from_str(ctx
, str
, -1);
1280 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1282 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1283 map
= isl_map_read_from_str(ctx
, str
, -1);
1284 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1286 flow
= isl_access_info_compute_flow(ai
);
1287 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1288 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1289 mm
.may
= isl_map_empty(dim
);
1291 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1293 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1294 " [1,10,0] -> [2,5,0] }";
1295 assert(map_is_equal(mm
.must
, str
));
1296 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1297 assert(map_is_equal(mm
.may
, str
));
1299 isl_map_free(mm
.must
);
1300 isl_map_free(mm
.may
);
1301 isl_flow_free(flow
);
1304 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1305 map
= isl_map_read_from_str(ctx
, str
, -1);
1306 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1308 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1309 map
= isl_map_read_from_str(ctx
, str
, -1);
1310 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1312 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1313 map
= isl_map_read_from_str(ctx
, str
, -1);
1314 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1316 flow
= isl_access_info_compute_flow(ai
);
1317 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1318 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1319 mm
.may
= isl_map_empty(dim
);
1321 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1323 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1324 assert(map_is_equal(mm
.must
, str
));
1325 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1326 assert(map_is_equal(mm
.may
, str
));
1328 isl_map_free(mm
.must
);
1329 isl_map_free(mm
.may
);
1330 isl_flow_free(flow
);
1333 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1334 map
= isl_map_read_from_str(ctx
, str
, -1);
1335 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1337 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1338 map
= isl_map_read_from_str(ctx
, str
, -1);
1339 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1341 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1342 map
= isl_map_read_from_str(ctx
, str
, -1);
1343 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1345 flow
= isl_access_info_compute_flow(ai
);
1346 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1347 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1348 mm
.may
= isl_map_empty(dim
);
1350 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1352 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1353 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1354 assert(map_is_equal(mm
.may
, str
));
1355 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1356 assert(map_is_equal(mm
.must
, str
));
1358 isl_map_free(mm
.must
);
1359 isl_map_free(mm
.may
);
1360 isl_flow_free(flow
);
1363 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1364 map
= isl_map_read_from_str(ctx
, str
, -1);
1365 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1367 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1368 map
= isl_map_read_from_str(ctx
, str
, -1);
1369 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1371 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1372 map
= isl_map_read_from_str(ctx
, str
, -1);
1373 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1375 flow
= isl_access_info_compute_flow(ai
);
1376 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1377 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1378 mm
.may
= isl_map_empty(dim
);
1380 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1382 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1383 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1384 assert(map_is_equal(mm
.may
, str
));
1385 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1386 assert(map_is_equal(mm
.must
, str
));
1388 isl_map_free(mm
.must
);
1389 isl_map_free(mm
.may
);
1390 isl_flow_free(flow
);
1393 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1394 map
= isl_map_read_from_str(ctx
, str
, -1);
1395 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1397 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1398 map
= isl_map_read_from_str(ctx
, str
, -1);
1399 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1401 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1402 map
= isl_map_read_from_str(ctx
, str
, -1);
1403 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1405 flow
= isl_access_info_compute_flow(ai
);
1406 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1407 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1408 mm
.may
= isl_map_empty(dim
);
1410 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1412 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1413 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1414 assert(map_is_equal(mm
.may
, str
));
1415 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1416 assert(map_is_equal(mm
.must
, str
));
1418 isl_map_free(mm
.must
);
1419 isl_map_free(mm
.may
);
1420 isl_flow_free(flow
);
1425 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1426 map
= isl_map_read_from_str(ctx
, str
, -1);
1427 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1429 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1430 map
= isl_map_read_from_str(ctx
, str
, -1);
1431 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1433 flow
= isl_access_info_compute_flow(ai
);
1434 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1435 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1436 mm
.may
= isl_map_empty(dim
);
1438 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1440 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1441 assert(map_is_equal(mm
.must
, str
));
1442 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1443 assert(map_is_equal(mm
.may
, str
));
1445 isl_map_free(mm
.must
);
1446 isl_map_free(mm
.may
);
1447 isl_flow_free(flow
);
1450 void test_sv(struct isl_ctx
*ctx
)
1455 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1456 map
= isl_map_read_from_str(ctx
, str
, -1);
1457 assert(isl_map_is_single_valued(map
));
1460 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1461 map
= isl_map_read_from_str(ctx
, str
, -1);
1462 assert(!isl_map_is_single_valued(map
));
1466 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1470 map
= isl_map_read_from_str(ctx
, str
, -1);
1472 assert(isl_map_is_bijective(map
));
1474 assert(!isl_map_is_bijective(map
));
1478 void test_bijective(struct isl_ctx
*ctx
)
1480 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1481 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1482 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1483 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1484 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1485 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1486 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1487 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1488 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1489 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1490 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1491 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1492 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1495 void test_pwqp(struct isl_ctx
*ctx
)
1499 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1501 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1502 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1504 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1507 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1508 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1510 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1512 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1514 isl_pw_qpolynomial_free(pwqp1
);
1516 str
= "{ [i] -> i }";
1517 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1518 str
= "{ [k] : exists a : k = 2a }";
1519 set
= isl_set_read_from_str(ctx
, str
, 0);
1520 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1521 str
= "{ [i] -> i }";
1522 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1524 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1526 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1528 isl_pw_qpolynomial_free(pwqp1
);
1530 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
1531 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1533 set
= isl_set_read_from_str(ctx
, str
, 0);
1534 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1535 str
= "{ [i] -> 16 }";
1536 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1538 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1540 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1542 isl_pw_qpolynomial_free(pwqp1
);
1544 str
= "{ [i] -> ([(i)/2]) }";
1545 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1546 str
= "{ [k] : exists a : k = 2a+1 }";
1547 set
= isl_set_read_from_str(ctx
, str
, 0);
1548 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1549 str
= "{ [i] -> -1/2 + 1/2 * i }";
1550 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1552 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1554 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1556 isl_pw_qpolynomial_free(pwqp1
);
1558 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
1559 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1560 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1561 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1563 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1565 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1567 isl_pw_qpolynomial_free(pwqp1
);
1569 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1570 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1571 str
= "{ [x] -> x }";
1572 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1574 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1576 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1578 isl_pw_qpolynomial_free(pwqp1
);
1581 void test_split_periods(isl_ctx
*ctx
)
1584 isl_pw_qpolynomial
*pwqp
;
1586 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1587 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1588 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1589 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1591 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1594 isl_pw_qpolynomial_free(pwqp
);
1597 void test_union(isl_ctx
*ctx
)
1600 isl_union_set
*uset1
, *uset2
;
1601 isl_union_map
*umap1
, *umap2
;
1603 str
= "{ [i] : 0 <= i <= 1 }";
1604 uset1
= isl_union_set_read_from_str(ctx
, str
);
1605 str
= "{ [1] -> [0] }";
1606 umap1
= isl_union_map_read_from_str(ctx
, str
);
1608 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1609 assert(isl_union_map_is_equal(umap1
, umap2
));
1611 isl_union_map_free(umap1
);
1612 isl_union_map_free(umap2
);
1614 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1615 umap1
= isl_union_map_read_from_str(ctx
, str
);
1616 str
= "{ A[i]; B[i] }";
1617 uset1
= isl_union_set_read_from_str(ctx
, str
);
1619 uset2
= isl_union_map_domain(umap1
);
1621 assert(isl_union_set_is_equal(uset1
, uset2
));
1623 isl_union_set_free(uset1
);
1624 isl_union_set_free(uset2
);
1627 void test_bound(isl_ctx
*ctx
)
1630 isl_pw_qpolynomial
*pwqp
;
1631 isl_pw_qpolynomial_fold
*pwf
;
1633 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1634 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1635 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1636 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 4);
1637 isl_pw_qpolynomial_fold_free(pwf
);
1640 void test_lift(isl_ctx
*ctx
)
1643 isl_basic_map
*bmap
;
1644 isl_basic_set
*bset
;
1646 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1647 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1648 bset
= isl_basic_set_lift(bset
);
1649 bmap
= isl_basic_map_from_range(bset
);
1650 bset
= isl_basic_map_domain(bmap
);
1651 isl_basic_set_free(bset
);
1654 void test_subset(isl_ctx
*ctx
)
1657 isl_set
*set1
, *set2
;
1659 str
= "{ [112, 0] }";
1660 set1
= isl_set_read_from_str(ctx
, str
, 0);
1661 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1662 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1663 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1664 set2
= isl_set_read_from_str(ctx
, str
, 0);
1665 assert(isl_set_is_subset(set1
, set2
));
1670 void test_factorize(isl_ctx
*ctx
)
1673 isl_basic_set
*bset
;
1676 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1677 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1678 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1679 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1680 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1681 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1682 "3i5 >= -2i0 - i2 + 3i4 }";
1683 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1684 f
= isl_basic_set_factorizer(bset
);
1686 isl_basic_set_free(bset
);
1687 isl_factorizer_free(f
);
1689 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1690 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1691 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1692 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1693 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1694 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1695 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1696 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1697 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1698 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1699 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1700 f
= isl_basic_set_factorizer(bset
);
1702 isl_basic_set_free(bset
);
1703 isl_factorizer_free(f
);
1708 struct isl_ctx
*ctx
;
1710 srcdir
= getenv("srcdir");
1713 ctx
= isl_ctx_alloc();
1714 test_factorize(ctx
);
1719 test_split_periods(ctx
);
1724 test_bijective(ctx
);
1728 test_construction(ctx
);
1731 test_application(ctx
);
1732 test_affine_hull(ctx
);
1733 test_convex_hull(ctx
);