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_ctx_private.h>
14 #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]]}");
58 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
59 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
61 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
62 map
= isl_map_read_from_str(ctx
, str
, -1);
63 str
= "{ [new, old] -> [o0, o1] : "
64 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
65 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
66 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
67 map2
= isl_map_read_from_str(ctx
, str
, -1);
68 assert(isl_map_is_equal(map
, map2
));
72 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
73 map
= isl_map_read_from_str(ctx
, str
, -1);
74 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
75 map2
= isl_map_read_from_str(ctx
, str
, -1);
76 assert(isl_map_is_equal(map
, map2
));
80 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
83 void test_read(struct isl_ctx
*ctx
)
85 char filename
[PATH_MAX
];
88 struct isl_basic_set
*bset1
, *bset2
;
89 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
91 n
= snprintf(filename
, sizeof(filename
),
92 "%s/test_inputs/set.omega", srcdir
);
93 assert(n
< sizeof(filename
));
94 input
= fopen(filename
, "r");
97 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
98 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
100 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
102 isl_basic_set_free(bset1
);
103 isl_basic_set_free(bset2
);
108 void test_bounded(struct isl_ctx
*ctx
)
113 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
114 bounded
= isl_set_is_bounded(set
);
118 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
119 bounded
= isl_set_is_bounded(set
);
123 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
124 bounded
= isl_set_is_bounded(set
);
129 /* Construct the basic set { [i] : 5 <= i <= N } */
130 void test_construction(struct isl_ctx
*ctx
)
134 struct isl_basic_set
*bset
;
135 struct isl_constraint
*c
;
139 dim
= isl_dim_set_alloc(ctx
, 1, 1);
140 bset
= isl_basic_set_universe(dim
);
142 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
143 isl_int_set_si(v
, -1);
144 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
145 isl_int_set_si(v
, 1);
146 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
147 bset
= isl_basic_set_add_constraint(bset
, c
);
149 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
150 isl_int_set_si(v
, 1);
151 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
152 isl_int_set_si(v
, -5);
153 isl_constraint_set_constant(c
, v
);
154 bset
= isl_basic_set_add_constraint(bset
, c
);
156 isl_basic_set_free(bset
);
161 void test_dim(struct isl_ctx
*ctx
)
164 isl_map
*map1
, *map2
;
166 map1
= isl_map_read_from_str(ctx
,
167 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
168 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
169 map2
= isl_map_read_from_str(ctx
,
170 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
171 assert(isl_map_is_equal(map1
, map2
));
174 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
175 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
176 assert(isl_map_is_equal(map1
, map2
));
181 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
182 map1
= isl_map_read_from_str(ctx
, str
, -1);
183 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
184 map2
= isl_map_read_from_str(ctx
, str
, -1);
185 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
186 assert(isl_map_is_equal(map1
, map2
));
192 void test_div(struct isl_ctx
*ctx
)
198 struct isl_basic_set
*bset
;
199 struct isl_constraint
*c
;
204 dim
= isl_dim_set_alloc(ctx
, 0, 1);
205 bset
= isl_basic_set_universe(dim
);
207 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
208 isl_int_set_si(v
, -1);
209 isl_constraint_set_constant(c
, v
);
210 isl_int_set_si(v
, 1);
211 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
212 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
213 c
= isl_constraint_add_div(c
, div
, &pos
);
214 isl_int_set_si(v
, 3);
215 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
216 bset
= isl_basic_set_add_constraint(bset
, c
);
218 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
219 isl_int_set_si(v
, 1);
220 isl_constraint_set_constant(c
, v
);
221 isl_int_set_si(v
, -1);
222 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
223 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
224 c
= isl_constraint_add_div(c
, div
, &pos
);
225 isl_int_set_si(v
, 3);
226 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
227 bset
= isl_basic_set_add_constraint(bset
, c
);
229 assert(bset
&& bset
->n_div
== 1);
230 isl_basic_set_free(bset
);
233 dim
= isl_dim_set_alloc(ctx
, 0, 1);
234 bset
= isl_basic_set_universe(dim
);
236 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
237 isl_int_set_si(v
, 1);
238 isl_constraint_set_constant(c
, v
);
239 isl_int_set_si(v
, -1);
240 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
241 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
242 c
= isl_constraint_add_div(c
, div
, &pos
);
243 isl_int_set_si(v
, 3);
244 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
245 bset
= isl_basic_set_add_constraint(bset
, c
);
247 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
248 isl_int_set_si(v
, -1);
249 isl_constraint_set_constant(c
, v
);
250 isl_int_set_si(v
, 1);
251 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
252 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
253 c
= isl_constraint_add_div(c
, div
, &pos
);
254 isl_int_set_si(v
, 3);
255 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
256 bset
= isl_basic_set_add_constraint(bset
, c
);
258 assert(bset
&& bset
->n_div
== 1);
259 isl_basic_set_free(bset
);
262 dim
= isl_dim_set_alloc(ctx
, 0, 1);
263 bset
= isl_basic_set_universe(dim
);
265 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
266 isl_int_set_si(v
, 1);
267 isl_constraint_set_constant(c
, v
);
268 isl_int_set_si(v
, -1);
269 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
270 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
271 c
= isl_constraint_add_div(c
, div
, &pos
);
272 isl_int_set_si(v
, 3);
273 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
274 bset
= isl_basic_set_add_constraint(bset
, c
);
276 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
277 isl_int_set_si(v
, -3);
278 isl_constraint_set_constant(c
, v
);
279 isl_int_set_si(v
, 1);
280 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
281 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
282 c
= isl_constraint_add_div(c
, div
, &pos
);
283 isl_int_set_si(v
, 4);
284 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
285 bset
= isl_basic_set_add_constraint(bset
, c
);
287 assert(bset
&& bset
->n_div
== 1);
288 isl_basic_set_free(bset
);
291 dim
= isl_dim_set_alloc(ctx
, 0, 1);
292 bset
= isl_basic_set_universe(dim
);
294 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
295 isl_int_set_si(v
, 2);
296 isl_constraint_set_constant(c
, v
);
297 isl_int_set_si(v
, -1);
298 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
299 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
300 c
= isl_constraint_add_div(c
, div
, &pos
);
301 isl_int_set_si(v
, 3);
302 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
303 bset
= isl_basic_set_add_constraint(bset
, c
);
305 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
306 isl_int_set_si(v
, -1);
307 isl_constraint_set_constant(c
, v
);
308 isl_int_set_si(v
, 1);
309 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
310 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
311 c
= isl_constraint_add_div(c
, div
, &pos
);
312 isl_int_set_si(v
, 6);
313 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
314 bset
= isl_basic_set_add_constraint(bset
, c
);
316 assert(isl_basic_set_is_empty(bset
));
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
, 3);
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
== 0);
340 isl_basic_set_free(bset
);
343 dim
= isl_dim_set_alloc(ctx
, 0, 2);
344 bset
= isl_basic_set_universe(dim
);
346 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
347 isl_int_set_si(v
, -1);
348 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
349 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
350 c
= isl_constraint_add_div(c
, div
, &pos
);
351 isl_int_set_si(v
, 6);
352 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
353 bset
= isl_basic_set_add_constraint(bset
, c
);
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 bset
= isl_basic_set_add_constraint(bset
, c
);
362 assert(bset
&& bset
->n_div
== 1);
363 isl_basic_set_free(bset
);
366 /* This test is a bit tricky. We set up an equality
368 * Normalization of divs creates _two_ divs
371 * Afterwards e0 is removed again because it has coefficient -1
372 * and we end up with the original equality and div again.
373 * Perhaps we can avoid the introduction of this temporary div.
375 dim
= isl_dim_set_alloc(ctx
, 0, 3);
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
, 2, 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 /* Test disabled for now */
393 assert(bset && bset->n_div == 1);
395 isl_basic_set_free(bset
);
398 dim
= isl_dim_set_alloc(ctx
, 0, 4);
399 bset
= isl_basic_set_universe(dim
);
401 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
402 isl_int_set_si(v
, -1);
403 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
404 isl_int_set_si(v
, -3);
405 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
406 isl_int_set_si(v
, -3);
407 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
408 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
409 c
= isl_constraint_add_div(c
, div
, &pos
);
410 isl_int_set_si(v
, 6);
411 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
412 bset
= isl_basic_set_add_constraint(bset
, c
);
414 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
415 isl_int_set_si(v
, -1);
416 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
417 isl_int_set_si(v
, 1);
418 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
419 isl_int_set_si(v
, 1);
420 isl_constraint_set_constant(c
, v
);
421 bset
= isl_basic_set_add_constraint(bset
, c
);
423 /* Test disabled for now */
425 assert(bset && bset->n_div == 1);
427 isl_basic_set_free(bset
);
430 dim
= isl_dim_set_alloc(ctx
, 0, 2);
431 bset
= isl_basic_set_universe(dim
);
433 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
434 isl_int_set_si(v
, 1);
435 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
436 isl_int_set_si(v
, -1);
437 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
438 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
439 c
= isl_constraint_add_div(c
, div
, &pos
);
440 isl_int_set_si(v
, -2);
441 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
442 bset
= isl_basic_set_add_constraint(bset
, c
);
444 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
445 isl_int_set_si(v
, -1);
446 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
447 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
448 c
= isl_constraint_add_div(c
, div
, &pos
);
449 isl_int_set_si(v
, 3);
450 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
451 isl_int_set_si(v
, 2);
452 isl_constraint_set_constant(c
, v
);
453 bset
= isl_basic_set_add_constraint(bset
, c
);
455 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
457 assert(!isl_basic_set_is_empty(bset
));
459 isl_basic_set_free(bset
);
462 dim
= isl_dim_set_alloc(ctx
, 0, 2);
463 bset
= isl_basic_set_universe(dim
);
465 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
466 isl_int_set_si(v
, 1);
467 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
468 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
469 c
= isl_constraint_add_div(c
, div
, &pos
);
470 isl_int_set_si(v
, -2);
471 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
472 bset
= isl_basic_set_add_constraint(bset
, c
);
474 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
476 isl_basic_set_free(bset
);
481 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
483 char filename
[PATH_MAX
];
486 struct isl_basic_set
*bset1
, *bset2
;
487 struct isl_basic_map
*bmap
;
489 n
= snprintf(filename
, sizeof(filename
),
490 "%s/test_inputs/%s.omega", srcdir
, name
);
491 assert(n
< sizeof(filename
));
492 input
= fopen(filename
, "r");
495 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
496 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
498 bset1
= isl_basic_set_apply(bset1
, bmap
);
500 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
502 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
504 isl_basic_set_free(bset1
);
505 isl_basic_set_free(bset2
);
510 void test_application(struct isl_ctx
*ctx
)
512 test_application_case(ctx
, "application");
513 test_application_case(ctx
, "application2");
516 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
518 char filename
[PATH_MAX
];
521 struct isl_basic_set
*bset1
, *bset2
;
523 n
= snprintf(filename
, sizeof(filename
),
524 "%s/test_inputs/%s.polylib", srcdir
, name
);
525 assert(n
< sizeof(filename
));
526 input
= fopen(filename
, "r");
529 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
530 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
532 bset1
= isl_basic_set_affine_hull(bset1
);
534 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
536 isl_basic_set_free(bset1
);
537 isl_basic_set_free(bset2
);
542 void test_affine_hull(struct isl_ctx
*ctx
)
544 test_affine_hull_case(ctx
, "affine2");
545 test_affine_hull_case(ctx
, "affine");
546 test_affine_hull_case(ctx
, "affine3");
549 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
551 char filename
[PATH_MAX
];
554 struct isl_basic_set
*bset1
, *bset2
;
557 n
= snprintf(filename
, sizeof(filename
),
558 "%s/test_inputs/%s.polylib", srcdir
, name
);
559 assert(n
< sizeof(filename
));
560 input
= fopen(filename
, "r");
563 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
564 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
566 set
= isl_basic_set_union(bset1
, bset2
);
567 bset1
= isl_set_convex_hull(set
);
569 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
571 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
573 isl_basic_set_free(bset1
);
574 isl_basic_set_free(bset2
);
579 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
581 const char *str1
, *str2
;
582 isl_set
*set1
, *set2
;
583 int orig_convex
= ctx
->opt
->convex
;
584 ctx
->opt
->convex
= convex
;
586 test_convex_hull_case(ctx
, "convex0");
587 test_convex_hull_case(ctx
, "convex1");
588 test_convex_hull_case(ctx
, "convex2");
589 test_convex_hull_case(ctx
, "convex3");
590 test_convex_hull_case(ctx
, "convex4");
591 test_convex_hull_case(ctx
, "convex5");
592 test_convex_hull_case(ctx
, "convex6");
593 test_convex_hull_case(ctx
, "convex7");
594 test_convex_hull_case(ctx
, "convex8");
595 test_convex_hull_case(ctx
, "convex9");
596 test_convex_hull_case(ctx
, "convex10");
597 test_convex_hull_case(ctx
, "convex11");
598 test_convex_hull_case(ctx
, "convex12");
599 test_convex_hull_case(ctx
, "convex13");
600 test_convex_hull_case(ctx
, "convex14");
601 test_convex_hull_case(ctx
, "convex15");
603 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
604 "(i0 = 1 and i1 = 0 and i2 = 1) or "
605 "(i0 = 0 and i1 = 0 and i2 = 0) }";
606 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
607 set1
= isl_set_read_from_str(ctx
, str1
, -1);
608 set2
= isl_set_read_from_str(ctx
, str2
, -1);
609 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
610 assert(isl_set_is_equal(set1
, set2
));
614 ctx
->opt
->convex
= orig_convex
;
617 void test_convex_hull(struct isl_ctx
*ctx
)
619 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
620 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
623 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
625 char filename
[PATH_MAX
];
628 struct isl_basic_set
*bset1
, *bset2
;
630 n
= snprintf(filename
, sizeof(filename
),
631 "%s/test_inputs/%s.polylib", srcdir
, name
);
632 assert(n
< sizeof(filename
));
633 input
= fopen(filename
, "r");
636 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
637 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
639 bset1
= isl_basic_set_gist(bset1
, bset2
);
641 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
643 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
645 isl_basic_set_free(bset1
);
646 isl_basic_set_free(bset2
);
651 void test_gist(struct isl_ctx
*ctx
)
654 isl_basic_set
*bset1
, *bset2
;
656 test_gist_case(ctx
, "gist1");
658 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
659 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
660 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
661 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
662 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
663 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
664 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
665 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
666 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
667 bset1
= isl_basic_set_read_from_str(ctx
, str
, -1);
668 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
669 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
670 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
671 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
672 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
673 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
674 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
675 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
676 bset2
= isl_basic_set_read_from_str(ctx
, str
, -1);
677 bset1
= isl_basic_set_gist(bset1
, bset2
);
678 assert(bset1
&& bset1
->n_div
== 0);
679 isl_basic_set_free(bset1
);
682 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
686 set
= isl_set_read_from_str(ctx
, str
, -1);
687 set
= isl_set_coalesce(set
);
688 set2
= isl_set_read_from_str(ctx
, str
, -1);
689 assert(isl_set_is_equal(set
, set2
));
691 assert(set
&& set
->n
== 1);
696 void test_coalesce(struct isl_ctx
*ctx
)
699 struct isl_set
*set
, *set2
;
700 struct isl_map
*map
, *map2
;
702 set
= isl_set_read_from_str(ctx
,
703 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
704 "y >= x & x >= 2 & 5 >= y }", -1);
705 set
= isl_set_coalesce(set
);
706 assert(set
&& set
->n
== 1);
709 set
= isl_set_read_from_str(ctx
,
710 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
711 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
712 set
= isl_set_coalesce(set
);
713 assert(set
&& set
->n
== 1);
716 set
= isl_set_read_from_str(ctx
,
717 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
718 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
719 set
= isl_set_coalesce(set
);
720 assert(set
&& set
->n
== 2);
723 set
= isl_set_read_from_str(ctx
,
724 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
725 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
726 set
= isl_set_coalesce(set
);
727 assert(set
&& set
->n
== 1);
730 set
= isl_set_read_from_str(ctx
,
731 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
732 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
733 set
= isl_set_coalesce(set
);
734 assert(set
&& set
->n
== 2);
737 set
= isl_set_read_from_str(ctx
,
738 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
739 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
740 set
= isl_set_coalesce(set
);
741 assert(set
&& set
->n
== 2);
744 set
= isl_set_read_from_str(ctx
,
745 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
746 "y >= 0 & x = 6 & y <= 6}", -1);
747 set
= isl_set_coalesce(set
);
748 assert(set
&& set
->n
== 1);
751 set
= isl_set_read_from_str(ctx
,
752 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
753 "y >= 0 & x = 7 & y <= 6}", -1);
754 set
= isl_set_coalesce(set
);
755 assert(set
&& set
->n
== 2);
758 set
= isl_set_read_from_str(ctx
,
759 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
760 "y >= 0 & x = 6 & y <= 5}", -1);
761 set
= isl_set_coalesce(set
);
762 assert(set
&& set
->n
== 1);
763 set2
= isl_set_read_from_str(ctx
,
764 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
765 "y >= 0 & x = 6 & y <= 5}", -1);
766 assert(isl_set_is_equal(set
, set2
));
770 set
= isl_set_read_from_str(ctx
,
771 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
772 "y >= 0 & x = 6 & y <= 7}", -1);
773 set
= isl_set_coalesce(set
);
774 assert(set
&& set
->n
== 2);
777 set
= isl_set_read_from_str(ctx
,
778 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
779 set
= isl_set_coalesce(set
);
780 assert(set
&& set
->n
== 1);
781 set2
= isl_set_read_from_str(ctx
,
782 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
783 assert(isl_set_is_equal(set
, set2
));
787 set
= isl_set_read_from_str(ctx
,
788 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
789 set
= isl_set_coalesce(set
);
790 set2
= isl_set_read_from_str(ctx
,
791 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
792 assert(isl_set_is_equal(set
, set2
));
796 set
= isl_set_read_from_str(ctx
,
797 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
798 "2 <= i and i <= n }", -1);
799 set
= isl_set_coalesce(set
);
800 assert(set
&& set
->n
== 1);
801 set2
= isl_set_read_from_str(ctx
,
802 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
803 "2 <= i and i <= n }", -1);
804 assert(isl_set_is_equal(set
, set2
));
808 map
= isl_map_read_from_str(ctx
,
809 "[n] -> { [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 i0 >= 8 + 2n and o0 >= 2 + i0 and "
813 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
814 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
815 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
816 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
817 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
818 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
819 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
820 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
821 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
822 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
823 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
824 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
825 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
826 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
827 map
= isl_map_coalesce(map
);
828 map2
= isl_map_read_from_str(ctx
,
829 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
830 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
831 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
832 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
833 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
834 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
835 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
836 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
837 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
838 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
839 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
840 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
841 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
842 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
843 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
844 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
845 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
846 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
847 assert(isl_map_is_equal(map
, map2
));
851 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
852 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
853 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
854 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
855 map
= isl_map_read_from_str(ctx
, str
, -1);
856 map
= isl_map_coalesce(map
);
857 map2
= isl_map_read_from_str(ctx
, str
, -1);
858 assert(isl_map_is_equal(map
, map2
));
862 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
863 "[o0, o1, o2, o3, o4, o5, o6] : "
864 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
865 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
866 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
867 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
868 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
869 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
870 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
871 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
872 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
873 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
874 "o6 >= i3 + i6 - o3 and M >= 0 and "
875 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
876 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
877 map
= isl_map_read_from_str(ctx
, str
, -1);
878 map
= isl_map_coalesce(map
);
879 map2
= isl_map_read_from_str(ctx
, str
, -1);
880 assert(isl_map_is_equal(map
, map2
));
884 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
885 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
886 "(o0 = 0 and M >= 2 and N >= 3) or "
887 "(M = 0 and o0 = 0 and N >= 3) }";
888 map
= isl_map_read_from_str(ctx
, str
, -1);
889 map
= isl_map_coalesce(map
);
890 map2
= isl_map_read_from_str(ctx
, str
, -1);
891 assert(isl_map_is_equal(map
, map2
));
895 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
896 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
897 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
898 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
899 map
= isl_map_read_from_str(ctx
, str
, -1);
900 map
= isl_map_coalesce(map
);
901 map2
= isl_map_read_from_str(ctx
, str
, -1);
902 assert(isl_map_is_equal(map
, map2
));
906 test_coalesce_set(ctx
,
907 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
908 "(i1 = M and M >= 1) }", 0);
909 test_coalesce_set(ctx
,
910 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
911 test_coalesce_set(ctx
,
912 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
913 "(y = 3 and x = 1) }", 1);
914 test_coalesce_set(ctx
,
915 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
916 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
917 "i1 <= M and i3 <= M and i4 <= M) or "
918 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
919 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
920 "i4 <= -1 + M) }", 1);
921 test_coalesce_set(ctx
,
922 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
923 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
924 test_coalesce_set(ctx
,
925 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
926 "-x - y + 1 >= 0 and -3 <= z <= 3;"
927 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
928 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
929 test_coalesce_set(ctx
,
930 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
931 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
932 test_coalesce_set(ctx
,
933 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
934 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
935 test_coalesce_set(ctx
, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
936 test_coalesce_set(ctx
, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
937 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
938 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
939 test_coalesce_set(ctx
, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
940 test_coalesce_set(ctx
, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
943 void test_closure(struct isl_ctx
*ctx
)
951 /* COCOA example 1 */
952 map
= isl_map_read_from_str(ctx
,
953 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
954 "1 <= i and i < n and 1 <= j and j < n or "
955 "i2 = i + 1 and j2 = j - 1 and "
956 "1 <= i and i < n and 2 <= j and j <= n }", -1);
957 map
= isl_map_power(map
, &exact
);
961 /* COCOA example 1 */
962 map
= isl_map_read_from_str(ctx
,
963 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
964 "1 <= i and i < n and 1 <= j and j < n or "
965 "i2 = i + 1 and j2 = j - 1 and "
966 "1 <= i and i < n and 2 <= j and j <= n }", -1);
967 map
= isl_map_transitive_closure(map
, &exact
);
969 map2
= isl_map_read_from_str(ctx
,
970 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
971 "1 <= i and i < n and 1 <= j and j <= n and "
972 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
973 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
974 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
975 assert(isl_map_is_equal(map
, map2
));
979 map
= isl_map_read_from_str(ctx
,
980 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
981 " 0 <= y and y <= n }", -1);
982 map
= isl_map_transitive_closure(map
, &exact
);
983 map2
= isl_map_read_from_str(ctx
,
984 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
985 " 0 <= y and y <= n }", -1);
986 assert(isl_map_is_equal(map
, map2
));
990 /* COCOA example 2 */
991 map
= isl_map_read_from_str(ctx
,
992 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
993 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
994 "i2 = i + 2 and j2 = j - 2 and "
995 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
996 map
= isl_map_transitive_closure(map
, &exact
);
998 map2
= isl_map_read_from_str(ctx
,
999 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1000 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1001 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1002 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1003 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
1004 assert(isl_map_is_equal(map
, map2
));
1008 /* COCOA Fig.2 left */
1009 map
= isl_map_read_from_str(ctx
,
1010 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1011 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1013 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1014 "j <= 2 i - 3 and j <= n - 2 or "
1015 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1016 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1017 map
= isl_map_transitive_closure(map
, &exact
);
1021 /* COCOA Fig.2 right */
1022 map
= isl_map_read_from_str(ctx
,
1023 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1024 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1026 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1027 "j <= 2 i - 4 and j <= n - 3 or "
1028 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1029 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1030 map
= isl_map_power(map
, &exact
);
1034 /* COCOA Fig.2 right */
1035 map
= isl_map_read_from_str(ctx
,
1036 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1037 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1039 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1040 "j <= 2 i - 4 and j <= n - 3 or "
1041 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1042 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1043 map
= isl_map_transitive_closure(map
, &exact
);
1045 map2
= isl_map_read_from_str(ctx
,
1046 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1047 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1048 "j <= n and 3 + i + 2 j <= 3 n and "
1049 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1050 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1051 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1052 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1053 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1054 assert(isl_map_is_equal(map
, map2
));
1058 /* COCOA Fig.1 right */
1059 dom
= isl_set_read_from_str(ctx
,
1060 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1061 "2 x - 3 y + 3 >= 0 }", -1);
1062 right
= isl_map_read_from_str(ctx
,
1063 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1064 up
= isl_map_read_from_str(ctx
,
1065 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1066 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1067 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1068 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1069 up
= isl_map_intersect_range(up
, dom
);
1070 map
= isl_map_union(up
, right
);
1071 map
= isl_map_transitive_closure(map
, &exact
);
1073 map2
= isl_map_read_from_str(ctx
,
1074 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1075 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1076 assert(isl_map_is_equal(map
, map2
));
1080 /* COCOA Theorem 1 counter example */
1081 map
= isl_map_read_from_str(ctx
,
1082 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1083 "i2 = 1 and j2 = j or "
1084 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1085 map
= isl_map_transitive_closure(map
, &exact
);
1089 map
= isl_map_read_from_str(ctx
,
1090 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1091 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1092 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1093 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1094 map
= isl_map_transitive_closure(map
, &exact
);
1098 /* Kelly et al 1996, fig 12 */
1099 map
= isl_map_read_from_str(ctx
,
1100 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1101 "1 <= i,j,j+1 <= n or "
1102 "j = n and j2 = 1 and i2 = i + 1 and "
1103 "1 <= i,i+1 <= n }", -1);
1104 map
= isl_map_transitive_closure(map
, &exact
);
1106 map2
= isl_map_read_from_str(ctx
,
1107 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1108 "1 <= i <= n and i = i2 or "
1109 "1 <= i < i2 <= n and 1 <= j <= n and "
1110 "1 <= j2 <= n }", -1);
1111 assert(isl_map_is_equal(map
, map2
));
1115 /* Omega's closure4 */
1116 map
= isl_map_read_from_str(ctx
,
1117 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1118 "1 <= x,y <= 10 or "
1119 "x2 = x + 1 and y2 = y and "
1120 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1121 map
= isl_map_transitive_closure(map
, &exact
);
1125 map
= isl_map_read_from_str(ctx
,
1126 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1127 map
= isl_map_transitive_closure(map
, &exact
);
1129 map2
= isl_map_read_from_str(ctx
,
1130 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1131 assert(isl_map_is_equal(map
, map2
));
1135 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1136 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1137 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1138 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1139 map
= isl_map_read_from_str(ctx
, str
, -1);
1140 map
= isl_map_transitive_closure(map
, &exact
);
1142 map2
= isl_map_read_from_str(ctx
, str
, -1);
1143 assert(isl_map_is_equal(map
, map2
));
1147 str
= "{[0] -> [1]; [2] -> [3]}";
1148 map
= isl_map_read_from_str(ctx
, str
, -1);
1149 map
= isl_map_transitive_closure(map
, &exact
);
1151 map2
= isl_map_read_from_str(ctx
, str
, -1);
1152 assert(isl_map_is_equal(map
, map2
));
1156 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1157 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1158 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1159 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1160 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1161 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1162 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1163 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1164 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1165 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1166 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1167 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1168 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1169 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1170 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1171 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1172 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1173 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1174 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1175 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1176 map
= isl_map_read_from_str(ctx
, str
, -1);
1177 map
= isl_map_transitive_closure(map
, NULL
);
1182 void test_lex(struct isl_ctx
*ctx
)
1187 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1188 map
= isl_map_lex_le(dim
);
1189 assert(!isl_map_is_empty(map
));
1193 void test_lexmin(struct isl_ctx
*ctx
)
1196 isl_map
*map
, *map2
;
1200 str
= "[p0, p1] -> { [] -> [] : "
1201 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1202 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1203 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1204 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1205 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1206 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1207 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1208 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1209 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1210 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1211 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1212 map
= isl_map_read_from_str(ctx
, str
, -1);
1213 map
= isl_map_lexmin(map
);
1216 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1217 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1218 set
= isl_set_read_from_str(ctx
, str
, -1);
1219 set
= isl_set_lexmax(set
);
1220 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1221 set2
= isl_set_read_from_str(ctx
, str
, -1);
1222 set
= isl_set_intersect(set
, set2
);
1223 assert(!isl_set_is_empty(set
));
1226 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1227 map
= isl_map_read_from_str(ctx
, str
, -1);
1228 map
= isl_map_lexmin(map
);
1229 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1230 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1231 map2
= isl_map_read_from_str(ctx
, str
, -1);
1232 assert(isl_map_is_equal(map
, map2
));
1236 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1237 map
= isl_map_read_from_str(ctx
, str
, -1);
1238 map2
= isl_map_copy(map
);
1239 map
= isl_map_lexmin(map
);
1240 assert(isl_map_is_equal(map
, map2
));
1244 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1245 map
= isl_map_read_from_str(ctx
, str
, -1);
1246 map
= isl_map_lexmin(map
);
1247 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1248 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1249 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1250 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1251 map2
= isl_map_read_from_str(ctx
, str
, -1);
1252 assert(isl_map_is_equal(map
, map2
));
1262 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1263 void *dep_user
, void *user
)
1265 struct must_may
*mm
= (struct must_may
*)user
;
1268 mm
->must
= isl_map_union(mm
->must
, dep
);
1270 mm
->may
= isl_map_union(mm
->may
, dep
);
1275 static int common_space(void *first
, void *second
)
1277 int depth
= *(int *)first
;
1281 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1289 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1290 equal
= isl_map_is_equal(map
, map2
);
1296 void test_dep(struct isl_ctx
*ctx
)
1301 isl_access_info
*ai
;
1308 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1309 map
= isl_map_read_from_str(ctx
, str
, -1);
1310 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1312 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1313 map
= isl_map_read_from_str(ctx
, str
, -1);
1314 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1316 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1317 map
= isl_map_read_from_str(ctx
, str
, -1);
1318 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1320 flow
= isl_access_info_compute_flow(ai
);
1321 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1322 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1323 mm
.may
= isl_map_empty(dim
);
1325 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1327 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1328 " [1,10,0] -> [2,5,0] }";
1329 assert(map_is_equal(mm
.must
, str
));
1330 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1331 assert(map_is_equal(mm
.may
, str
));
1333 isl_map_free(mm
.must
);
1334 isl_map_free(mm
.may
);
1335 isl_flow_free(flow
);
1338 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1339 map
= isl_map_read_from_str(ctx
, str
, -1);
1340 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1342 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1343 map
= isl_map_read_from_str(ctx
, str
, -1);
1344 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1346 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1347 map
= isl_map_read_from_str(ctx
, str
, -1);
1348 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1350 flow
= isl_access_info_compute_flow(ai
);
1351 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1352 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1353 mm
.may
= isl_map_empty(dim
);
1355 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1357 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1358 assert(map_is_equal(mm
.must
, str
));
1359 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1360 assert(map_is_equal(mm
.may
, str
));
1362 isl_map_free(mm
.must
);
1363 isl_map_free(mm
.may
);
1364 isl_flow_free(flow
);
1367 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1368 map
= isl_map_read_from_str(ctx
, str
, -1);
1369 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1371 str
= "{ [0,i,0] -> [i] : 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 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1376 map
= isl_map_read_from_str(ctx
, str
, -1);
1377 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1379 flow
= isl_access_info_compute_flow(ai
);
1380 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1381 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1382 mm
.may
= isl_map_empty(dim
);
1384 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1386 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1387 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1388 assert(map_is_equal(mm
.may
, str
));
1389 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1390 assert(map_is_equal(mm
.must
, str
));
1392 isl_map_free(mm
.must
);
1393 isl_map_free(mm
.may
);
1394 isl_flow_free(flow
);
1397 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1398 map
= isl_map_read_from_str(ctx
, str
, -1);
1399 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1401 str
= "{ [0,i,0] -> [i] : 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 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1406 map
= isl_map_read_from_str(ctx
, str
, -1);
1407 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1409 flow
= isl_access_info_compute_flow(ai
);
1410 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1411 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1412 mm
.may
= isl_map_empty(dim
);
1414 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1416 str
= "{ [0,i,0] -> [0,i,2] : 0 <= i <= 10; "
1417 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1418 assert(map_is_equal(mm
.may
, str
));
1419 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1420 assert(map_is_equal(mm
.must
, str
));
1422 isl_map_free(mm
.must
);
1423 isl_map_free(mm
.may
);
1424 isl_flow_free(flow
);
1427 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1428 map
= isl_map_read_from_str(ctx
, str
, -1);
1429 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1431 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1432 map
= isl_map_read_from_str(ctx
, str
, -1);
1433 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1435 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1436 map
= isl_map_read_from_str(ctx
, str
, -1);
1437 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1439 flow
= isl_access_info_compute_flow(ai
);
1440 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1441 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1442 mm
.may
= isl_map_empty(dim
);
1444 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1446 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1447 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1448 assert(map_is_equal(mm
.may
, str
));
1449 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1450 assert(map_is_equal(mm
.must
, str
));
1452 isl_map_free(mm
.must
);
1453 isl_map_free(mm
.may
);
1454 isl_flow_free(flow
);
1459 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1460 map
= isl_map_read_from_str(ctx
, str
, -1);
1461 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1463 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1464 map
= isl_map_read_from_str(ctx
, str
, -1);
1465 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1467 flow
= isl_access_info_compute_flow(ai
);
1468 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1469 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1470 mm
.may
= isl_map_empty(dim
);
1472 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1474 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1475 assert(map_is_equal(mm
.must
, str
));
1476 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1477 assert(map_is_equal(mm
.may
, str
));
1479 isl_map_free(mm
.must
);
1480 isl_map_free(mm
.may
);
1481 isl_flow_free(flow
);
1484 void test_sv(struct isl_ctx
*ctx
)
1489 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1490 map
= isl_map_read_from_str(ctx
, str
, -1);
1491 assert(isl_map_is_single_valued(map
));
1494 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1495 map
= isl_map_read_from_str(ctx
, str
, -1);
1496 assert(!isl_map_is_single_valued(map
));
1500 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1504 map
= isl_map_read_from_str(ctx
, str
, -1);
1506 assert(isl_map_is_bijective(map
));
1508 assert(!isl_map_is_bijective(map
));
1512 void test_bijective(struct isl_ctx
*ctx
)
1514 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1515 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1516 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1517 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1518 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1519 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1520 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1521 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1522 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1523 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1524 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1525 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1526 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1529 void test_pwqp(struct isl_ctx
*ctx
)
1533 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1535 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1536 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1538 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1541 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1542 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1544 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1546 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1548 isl_pw_qpolynomial_free(pwqp1
);
1550 str
= "{ [i] -> i }";
1551 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1552 str
= "{ [k] : exists a : k = 2a }";
1553 set
= isl_set_read_from_str(ctx
, str
, 0);
1554 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1555 str
= "{ [i] -> i }";
1556 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1558 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1560 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1562 isl_pw_qpolynomial_free(pwqp1
);
1564 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
1565 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1567 set
= isl_set_read_from_str(ctx
, str
, 0);
1568 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1569 str
= "{ [i] -> 16 }";
1570 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1572 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1574 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1576 isl_pw_qpolynomial_free(pwqp1
);
1578 str
= "{ [i] -> ([(i)/2]) }";
1579 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1580 str
= "{ [k] : exists a : k = 2a+1 }";
1581 set
= isl_set_read_from_str(ctx
, str
, 0);
1582 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1583 str
= "{ [i] -> -1/2 + 1/2 * i }";
1584 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1586 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1588 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1590 isl_pw_qpolynomial_free(pwqp1
);
1592 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
1593 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1594 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1595 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1597 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1599 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1601 isl_pw_qpolynomial_free(pwqp1
);
1603 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1604 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1605 str
= "{ [x] -> x }";
1606 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1608 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1610 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1612 isl_pw_qpolynomial_free(pwqp1
);
1615 void test_split_periods(isl_ctx
*ctx
)
1618 isl_pw_qpolynomial
*pwqp
;
1620 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1621 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1622 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1623 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1625 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1628 isl_pw_qpolynomial_free(pwqp
);
1631 void test_union(isl_ctx
*ctx
)
1634 isl_union_set
*uset1
, *uset2
;
1635 isl_union_map
*umap1
, *umap2
;
1637 str
= "{ [i] : 0 <= i <= 1 }";
1638 uset1
= isl_union_set_read_from_str(ctx
, str
);
1639 str
= "{ [1] -> [0] }";
1640 umap1
= isl_union_map_read_from_str(ctx
, str
);
1642 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1643 assert(isl_union_map_is_equal(umap1
, umap2
));
1645 isl_union_map_free(umap1
);
1646 isl_union_map_free(umap2
);
1648 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1649 umap1
= isl_union_map_read_from_str(ctx
, str
);
1650 str
= "{ A[i]; B[i] }";
1651 uset1
= isl_union_set_read_from_str(ctx
, str
);
1653 uset2
= isl_union_map_domain(umap1
);
1655 assert(isl_union_set_is_equal(uset1
, uset2
));
1657 isl_union_set_free(uset1
);
1658 isl_union_set_free(uset2
);
1661 void test_bound(isl_ctx
*ctx
)
1664 isl_pw_qpolynomial
*pwqp
;
1665 isl_pw_qpolynomial_fold
*pwf
;
1667 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1668 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1669 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1670 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 4);
1671 isl_pw_qpolynomial_fold_free(pwf
);
1673 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1674 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1675 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1676 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 1);
1677 isl_pw_qpolynomial_fold_free(pwf
);
1680 void test_lift(isl_ctx
*ctx
)
1683 isl_basic_map
*bmap
;
1684 isl_basic_set
*bset
;
1686 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1687 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1688 bset
= isl_basic_set_lift(bset
);
1689 bmap
= isl_basic_map_from_range(bset
);
1690 bset
= isl_basic_map_domain(bmap
);
1691 isl_basic_set_free(bset
);
1694 void test_subset(isl_ctx
*ctx
)
1697 isl_set
*set1
, *set2
;
1699 str
= "{ [112, 0] }";
1700 set1
= isl_set_read_from_str(ctx
, str
, 0);
1701 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1702 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1703 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1704 set2
= isl_set_read_from_str(ctx
, str
, 0);
1705 assert(isl_set_is_subset(set1
, set2
));
1710 void test_factorize(isl_ctx
*ctx
)
1713 isl_basic_set
*bset
;
1716 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1717 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1718 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1719 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1720 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1721 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1722 "3i5 >= -2i0 - i2 + 3i4 }";
1723 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1724 f
= isl_basic_set_factorizer(bset
);
1726 isl_basic_set_free(bset
);
1727 isl_factorizer_free(f
);
1729 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1730 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1731 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1732 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1733 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1734 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1735 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1736 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1737 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1738 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1739 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1740 f
= isl_basic_set_factorizer(bset
);
1742 isl_basic_set_free(bset
);
1743 isl_factorizer_free(f
);
1748 struct isl_ctx
*ctx
;
1750 srcdir
= getenv("srcdir");
1753 ctx
= isl_ctx_alloc();
1754 test_factorize(ctx
);
1759 test_split_periods(ctx
);
1764 test_bijective(ctx
);
1768 test_construction(ctx
);
1771 test_application(ctx
);
1772 test_affine_hull(ctx
);
1773 test_convex_hull(ctx
);