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_map_equal(isl_ctx
*ctx
, const char *str
, const char *str2
)
37 map
= isl_map_read_from_str(ctx
, str
, -1);
38 map2
= isl_map_read_from_str(ctx
, str2
, -1);
39 assert(map
&& map2
&& isl_map_is_equal(map
, map2
));
44 void test_parse_pwqp(isl_ctx
*ctx
, const char *str
)
46 isl_pw_qpolynomial
*pwqp
;
48 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
50 isl_pw_qpolynomial_free(pwqp
);
53 void test_parse(struct isl_ctx
*ctx
)
56 const char *str
, *str2
;
58 str
= "{ [i] -> [-i] }";
59 map
= isl_map_read_from_str(ctx
, str
, -1);
63 str
= "{ A[i] -> L[([i/3])] }";
64 map
= isl_map_read_from_str(ctx
, str
, -1);
68 test_parse_map(ctx
, "{[[s] -> A[i]] -> [[s+1] -> A[i]]}");
69 test_parse_map(ctx
, "{ [p1, y1, y2] -> [2, y1, y2] : "
70 "p1 = 1 && (y1 <= y2 || y2 = 0) }");
72 str
= "{ [x,y] : [([x/2]+y)/3] >= 1 }";
73 str2
= "{ [x, y] : 2y >= 6 - x }";
74 test_parse_map_equal(ctx
, str
, str2
);
76 test_parse_map_equal(ctx
, "{ [x,y] : x <= min(y, 2*y+3) }",
77 "{ [x,y] : x <= y, 2*y + 3 }");
78 str
= "{ [x, y] : (y <= x and y >= -3) or (2y <= -3 + x and y <= -4) }";
79 test_parse_map_equal(ctx
, "{ [x,y] : x >= min(y, 2*y+3) }", str
);
81 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
82 map
= isl_map_read_from_str(ctx
, str
, -1);
83 str
= "{ [new, old] -> [o0, o1] : "
84 "exists (e0 = [(-1 - new + o0)/2], e1 = [(-1 - old + o1)/2]: "
85 "2e0 = -1 - new + o0 and 2e1 = -1 - old + o1 and o0 >= 0 and "
86 "o0 <= 1 and o1 >= 0 and o1 <= 1) }";
87 map2
= isl_map_read_from_str(ctx
, str
, -1);
88 assert(isl_map_is_equal(map
, map2
));
92 str
= "{[new,old] -> [new+1-2*[(new+1)/2],old+1-2*[(old+1)/2]]}";
93 map
= isl_map_read_from_str(ctx
, str
, -1);
94 str
= "{[new,old] -> [(new+1)%2,(old+1)%2]}";
95 map2
= isl_map_read_from_str(ctx
, str
, -1);
96 assert(isl_map_is_equal(map
, map2
));
100 str
= "[n] -> { [c1] : c1>=0 and c1<=floord(n-4,3) }";
101 str2
= "[n] -> { [c1] : c1 >= 0 and 3c1 <= -4 + n }";
102 test_parse_map_equal(ctx
, str
, str2
);
104 test_parse_pwqp(ctx
, "{ [i] -> i + [ (i + [i/3])/2 ] }");
107 void test_read(struct isl_ctx
*ctx
)
109 char filename
[PATH_MAX
];
112 struct isl_basic_set
*bset1
, *bset2
;
113 const char *str
= "{[y]: Exists ( alpha : 2alpha = y)}";
115 n
= snprintf(filename
, sizeof(filename
),
116 "%s/test_inputs/set.omega", srcdir
);
117 assert(n
< sizeof(filename
));
118 input
= fopen(filename
, "r");
121 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
122 bset2
= isl_basic_set_read_from_str(ctx
, str
, 0);
124 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
126 isl_basic_set_free(bset1
);
127 isl_basic_set_free(bset2
);
132 void test_bounded(struct isl_ctx
*ctx
)
137 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : 0 <= i <= n }", -1);
138 bounded
= isl_set_is_bounded(set
);
142 set
= isl_set_read_from_str(ctx
, "{[n, i] : 0 <= i <= n }", -1);
143 bounded
= isl_set_is_bounded(set
);
147 set
= isl_set_read_from_str(ctx
, "[n] -> {[i] : i <= n }", -1);
148 bounded
= isl_set_is_bounded(set
);
153 /* Construct the basic set { [i] : 5 <= i <= N } */
154 void test_construction(struct isl_ctx
*ctx
)
158 struct isl_basic_set
*bset
;
159 struct isl_constraint
*c
;
163 dim
= isl_dim_set_alloc(ctx
, 1, 1);
164 bset
= isl_basic_set_universe(dim
);
166 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
167 isl_int_set_si(v
, -1);
168 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
169 isl_int_set_si(v
, 1);
170 isl_constraint_set_coefficient(c
, isl_dim_param
, 0, v
);
171 bset
= isl_basic_set_add_constraint(bset
, c
);
173 c
= isl_inequality_alloc(isl_basic_set_get_dim(bset
));
174 isl_int_set_si(v
, 1);
175 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
176 isl_int_set_si(v
, -5);
177 isl_constraint_set_constant(c
, v
);
178 bset
= isl_basic_set_add_constraint(bset
, c
);
180 isl_basic_set_free(bset
);
185 void test_dim(struct isl_ctx
*ctx
)
188 isl_map
*map1
, *map2
;
190 map1
= isl_map_read_from_str(ctx
,
191 "[n] -> { [i] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
192 map1
= isl_map_add_dims(map1
, isl_dim_in
, 1);
193 map2
= isl_map_read_from_str(ctx
,
194 "[n] -> { [i,k] -> [j] : exists (a = [i/10] : i - 10a <= n ) }", -1);
195 assert(isl_map_is_equal(map1
, map2
));
198 map1
= isl_map_project_out(map1
, isl_dim_in
, 0, 1);
199 map2
= isl_map_read_from_str(ctx
, "[n] -> { [i] -> [j] : n >= 0 }", -1);
200 assert(isl_map_is_equal(map1
, map2
));
205 str
= "[n] -> { [i] -> [] : exists a : 0 <= i <= n and i = 2 a }";
206 map1
= isl_map_read_from_str(ctx
, str
, -1);
207 str
= "{ [i] -> [j] : exists a : 0 <= i <= j and i = 2 a }";
208 map2
= isl_map_read_from_str(ctx
, str
, -1);
209 map1
= isl_map_move_dims(map1
, isl_dim_out
, 0, isl_dim_param
, 0, 1);
210 assert(isl_map_is_equal(map1
, map2
));
216 void test_div(struct isl_ctx
*ctx
)
222 struct isl_basic_set
*bset
;
223 struct isl_constraint
*c
;
228 dim
= isl_dim_set_alloc(ctx
, 0, 1);
229 bset
= isl_basic_set_universe(dim
);
231 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
232 isl_int_set_si(v
, -1);
233 isl_constraint_set_constant(c
, v
);
234 isl_int_set_si(v
, 1);
235 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
236 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
237 c
= isl_constraint_add_div(c
, div
, &pos
);
238 isl_int_set_si(v
, 3);
239 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
240 bset
= isl_basic_set_add_constraint(bset
, c
);
242 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
243 isl_int_set_si(v
, 1);
244 isl_constraint_set_constant(c
, v
);
245 isl_int_set_si(v
, -1);
246 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
247 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
248 c
= isl_constraint_add_div(c
, div
, &pos
);
249 isl_int_set_si(v
, 3);
250 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
251 bset
= isl_basic_set_add_constraint(bset
, c
);
253 assert(bset
&& bset
->n_div
== 1);
254 isl_basic_set_free(bset
);
257 dim
= isl_dim_set_alloc(ctx
, 0, 1);
258 bset
= isl_basic_set_universe(dim
);
260 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
261 isl_int_set_si(v
, 1);
262 isl_constraint_set_constant(c
, v
);
263 isl_int_set_si(v
, -1);
264 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
265 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
266 c
= isl_constraint_add_div(c
, div
, &pos
);
267 isl_int_set_si(v
, 3);
268 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
269 bset
= isl_basic_set_add_constraint(bset
, c
);
271 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
272 isl_int_set_si(v
, -1);
273 isl_constraint_set_constant(c
, v
);
274 isl_int_set_si(v
, 1);
275 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
276 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
277 c
= isl_constraint_add_div(c
, div
, &pos
);
278 isl_int_set_si(v
, 3);
279 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
280 bset
= isl_basic_set_add_constraint(bset
, c
);
282 assert(bset
&& bset
->n_div
== 1);
283 isl_basic_set_free(bset
);
286 dim
= isl_dim_set_alloc(ctx
, 0, 1);
287 bset
= isl_basic_set_universe(dim
);
289 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
290 isl_int_set_si(v
, 1);
291 isl_constraint_set_constant(c
, v
);
292 isl_int_set_si(v
, -1);
293 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
294 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
295 c
= isl_constraint_add_div(c
, div
, &pos
);
296 isl_int_set_si(v
, 3);
297 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
298 bset
= isl_basic_set_add_constraint(bset
, c
);
300 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
301 isl_int_set_si(v
, -3);
302 isl_constraint_set_constant(c
, v
);
303 isl_int_set_si(v
, 1);
304 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
305 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
306 c
= isl_constraint_add_div(c
, div
, &pos
);
307 isl_int_set_si(v
, 4);
308 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
309 bset
= isl_basic_set_add_constraint(bset
, c
);
311 assert(bset
&& bset
->n_div
== 1);
312 isl_basic_set_free(bset
);
315 dim
= isl_dim_set_alloc(ctx
, 0, 1);
316 bset
= isl_basic_set_universe(dim
);
318 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
319 isl_int_set_si(v
, 2);
320 isl_constraint_set_constant(c
, v
);
321 isl_int_set_si(v
, -1);
322 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
323 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
324 c
= isl_constraint_add_div(c
, div
, &pos
);
325 isl_int_set_si(v
, 3);
326 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
327 bset
= isl_basic_set_add_constraint(bset
, c
);
329 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
330 isl_int_set_si(v
, -1);
331 isl_constraint_set_constant(c
, v
);
332 isl_int_set_si(v
, 1);
333 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
334 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
335 c
= isl_constraint_add_div(c
, div
, &pos
);
336 isl_int_set_si(v
, 6);
337 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
338 bset
= isl_basic_set_add_constraint(bset
, c
);
340 assert(isl_basic_set_is_empty(bset
));
341 isl_basic_set_free(bset
);
344 dim
= isl_dim_set_alloc(ctx
, 0, 2);
345 bset
= isl_basic_set_universe(dim
);
347 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
348 isl_int_set_si(v
, -1);
349 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
350 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
351 c
= isl_constraint_add_div(c
, div
, &pos
);
352 isl_int_set_si(v
, 3);
353 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
354 bset
= isl_basic_set_add_constraint(bset
, c
);
356 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
357 isl_int_set_si(v
, 1);
358 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
359 isl_int_set_si(v
, -3);
360 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
361 bset
= isl_basic_set_add_constraint(bset
, c
);
363 assert(bset
&& bset
->n_div
== 0);
364 isl_basic_set_free(bset
);
367 dim
= isl_dim_set_alloc(ctx
, 0, 2);
368 bset
= isl_basic_set_universe(dim
);
370 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
371 isl_int_set_si(v
, -1);
372 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
373 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
374 c
= isl_constraint_add_div(c
, div
, &pos
);
375 isl_int_set_si(v
, 6);
376 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
377 bset
= isl_basic_set_add_constraint(bset
, c
);
379 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
380 isl_int_set_si(v
, 1);
381 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
382 isl_int_set_si(v
, -3);
383 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
384 bset
= isl_basic_set_add_constraint(bset
, c
);
386 assert(bset
&& bset
->n_div
== 1);
387 isl_basic_set_free(bset
);
390 /* This test is a bit tricky. We set up an equality
392 * Normalization of divs creates _two_ divs
395 * Afterwards e0 is removed again because it has coefficient -1
396 * and we end up with the original equality and div again.
397 * Perhaps we can avoid the introduction of this temporary div.
399 dim
= isl_dim_set_alloc(ctx
, 0, 3);
400 bset
= isl_basic_set_universe(dim
);
402 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
403 isl_int_set_si(v
, -1);
404 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
405 isl_int_set_si(v
, -3);
406 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
407 isl_int_set_si(v
, -3);
408 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
409 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
410 c
= isl_constraint_add_div(c
, div
, &pos
);
411 isl_int_set_si(v
, 6);
412 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
413 bset
= isl_basic_set_add_constraint(bset
, c
);
415 /* Test disabled for now */
417 assert(bset && bset->n_div == 1);
419 isl_basic_set_free(bset
);
422 dim
= isl_dim_set_alloc(ctx
, 0, 4);
423 bset
= isl_basic_set_universe(dim
);
425 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
426 isl_int_set_si(v
, -1);
427 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
428 isl_int_set_si(v
, -3);
429 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
430 isl_int_set_si(v
, -3);
431 isl_constraint_set_coefficient(c
, isl_dim_set
, 3, v
);
432 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
433 c
= isl_constraint_add_div(c
, div
, &pos
);
434 isl_int_set_si(v
, 6);
435 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
436 bset
= isl_basic_set_add_constraint(bset
, c
);
438 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
439 isl_int_set_si(v
, -1);
440 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
441 isl_int_set_si(v
, 1);
442 isl_constraint_set_coefficient(c
, isl_dim_set
, 2, v
);
443 isl_int_set_si(v
, 1);
444 isl_constraint_set_constant(c
, v
);
445 bset
= isl_basic_set_add_constraint(bset
, c
);
447 /* Test disabled for now */
449 assert(bset && bset->n_div == 1);
451 isl_basic_set_free(bset
);
454 dim
= isl_dim_set_alloc(ctx
, 0, 2);
455 bset
= isl_basic_set_universe(dim
);
457 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
458 isl_int_set_si(v
, 1);
459 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
460 isl_int_set_si(v
, -1);
461 isl_constraint_set_coefficient(c
, isl_dim_set
, 1, v
);
462 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
463 c
= isl_constraint_add_div(c
, div
, &pos
);
464 isl_int_set_si(v
, -2);
465 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
466 bset
= isl_basic_set_add_constraint(bset
, c
);
468 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
469 isl_int_set_si(v
, -1);
470 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
471 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
472 c
= isl_constraint_add_div(c
, div
, &pos
);
473 isl_int_set_si(v
, 3);
474 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
475 isl_int_set_si(v
, 2);
476 isl_constraint_set_constant(c
, v
);
477 bset
= isl_basic_set_add_constraint(bset
, c
);
479 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
481 assert(!isl_basic_set_is_empty(bset
));
483 isl_basic_set_free(bset
);
486 dim
= isl_dim_set_alloc(ctx
, 0, 2);
487 bset
= isl_basic_set_universe(dim
);
489 c
= isl_equality_alloc(isl_basic_set_get_dim(bset
));
490 isl_int_set_si(v
, 1);
491 isl_constraint_set_coefficient(c
, isl_dim_set
, 0, v
);
492 div
= isl_div_alloc(isl_basic_set_get_dim(bset
));
493 c
= isl_constraint_add_div(c
, div
, &pos
);
494 isl_int_set_si(v
, -2);
495 isl_constraint_set_coefficient(c
, isl_dim_div
, pos
, v
);
496 bset
= isl_basic_set_add_constraint(bset
, c
);
498 bset
= isl_basic_set_fix_si(bset
, isl_dim_set
, 0, 2);
500 isl_basic_set_free(bset
);
505 void test_application_case(struct isl_ctx
*ctx
, const char *name
)
507 char filename
[PATH_MAX
];
510 struct isl_basic_set
*bset1
, *bset2
;
511 struct isl_basic_map
*bmap
;
513 n
= snprintf(filename
, sizeof(filename
),
514 "%s/test_inputs/%s.omega", srcdir
, name
);
515 assert(n
< sizeof(filename
));
516 input
= fopen(filename
, "r");
519 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
520 bmap
= isl_basic_map_read_from_file(ctx
, input
, 0);
522 bset1
= isl_basic_set_apply(bset1
, bmap
);
524 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
526 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
528 isl_basic_set_free(bset1
);
529 isl_basic_set_free(bset2
);
534 void test_application(struct isl_ctx
*ctx
)
536 test_application_case(ctx
, "application");
537 test_application_case(ctx
, "application2");
540 void test_affine_hull_case(struct isl_ctx
*ctx
, const char *name
)
542 char filename
[PATH_MAX
];
545 struct isl_basic_set
*bset1
, *bset2
;
547 n
= snprintf(filename
, sizeof(filename
),
548 "%s/test_inputs/%s.polylib", srcdir
, name
);
549 assert(n
< sizeof(filename
));
550 input
= fopen(filename
, "r");
553 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
554 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
556 bset1
= isl_basic_set_affine_hull(bset1
);
558 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
560 isl_basic_set_free(bset1
);
561 isl_basic_set_free(bset2
);
566 void test_affine_hull(struct isl_ctx
*ctx
)
568 test_affine_hull_case(ctx
, "affine2");
569 test_affine_hull_case(ctx
, "affine");
570 test_affine_hull_case(ctx
, "affine3");
573 void test_convex_hull_case(struct isl_ctx
*ctx
, const char *name
)
575 char filename
[PATH_MAX
];
578 struct isl_basic_set
*bset1
, *bset2
;
581 n
= snprintf(filename
, sizeof(filename
),
582 "%s/test_inputs/%s.polylib", srcdir
, name
);
583 assert(n
< sizeof(filename
));
584 input
= fopen(filename
, "r");
587 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
588 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
590 set
= isl_basic_set_union(bset1
, bset2
);
591 bset1
= isl_set_convex_hull(set
);
593 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
595 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
597 isl_basic_set_free(bset1
);
598 isl_basic_set_free(bset2
);
603 void test_convex_hull_algo(struct isl_ctx
*ctx
, int convex
)
605 const char *str1
, *str2
;
606 isl_set
*set1
, *set2
;
607 int orig_convex
= ctx
->opt
->convex
;
608 ctx
->opt
->convex
= convex
;
610 test_convex_hull_case(ctx
, "convex0");
611 test_convex_hull_case(ctx
, "convex1");
612 test_convex_hull_case(ctx
, "convex2");
613 test_convex_hull_case(ctx
, "convex3");
614 test_convex_hull_case(ctx
, "convex4");
615 test_convex_hull_case(ctx
, "convex5");
616 test_convex_hull_case(ctx
, "convex6");
617 test_convex_hull_case(ctx
, "convex7");
618 test_convex_hull_case(ctx
, "convex8");
619 test_convex_hull_case(ctx
, "convex9");
620 test_convex_hull_case(ctx
, "convex10");
621 test_convex_hull_case(ctx
, "convex11");
622 test_convex_hull_case(ctx
, "convex12");
623 test_convex_hull_case(ctx
, "convex13");
624 test_convex_hull_case(ctx
, "convex14");
625 test_convex_hull_case(ctx
, "convex15");
627 str1
= "{ [i0, i1, i2] : (i2 = 1 and i0 = 0 and i1 >= 0) or "
628 "(i0 = 1 and i1 = 0 and i2 = 1) or "
629 "(i0 = 0 and i1 = 0 and i2 = 0) }";
630 str2
= "{ [i0, i1, i2] : i0 >= 0 and i2 >= i0 and i2 <= 1 and i1 >= 0 }";
631 set1
= isl_set_read_from_str(ctx
, str1
, -1);
632 set2
= isl_set_read_from_str(ctx
, str2
, -1);
633 set1
= isl_set_from_basic_set(isl_set_convex_hull(set1
));
634 assert(isl_set_is_equal(set1
, set2
));
638 ctx
->opt
->convex
= orig_convex
;
641 void test_convex_hull(struct isl_ctx
*ctx
)
643 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_FM
);
644 test_convex_hull_algo(ctx
, ISL_CONVEX_HULL_WRAP
);
647 void test_gist_case(struct isl_ctx
*ctx
, const char *name
)
649 char filename
[PATH_MAX
];
652 struct isl_basic_set
*bset1
, *bset2
;
654 n
= snprintf(filename
, sizeof(filename
),
655 "%s/test_inputs/%s.polylib", srcdir
, name
);
656 assert(n
< sizeof(filename
));
657 input
= fopen(filename
, "r");
660 bset1
= isl_basic_set_read_from_file(ctx
, input
, 0);
661 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
663 bset1
= isl_basic_set_gist(bset1
, bset2
);
665 bset2
= isl_basic_set_read_from_file(ctx
, input
, 0);
667 assert(isl_basic_set_is_equal(bset1
, bset2
) == 1);
669 isl_basic_set_free(bset1
);
670 isl_basic_set_free(bset2
);
675 void test_gist(struct isl_ctx
*ctx
)
678 isl_basic_set
*bset1
, *bset2
;
680 test_gist_case(ctx
, "gist1");
682 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : "
683 "exists (e0 = [(15 + p0 + 15p6 + 15p10)/16], e1 = [(p5)/8], "
684 "e2 = [(p6)/128], e3 = [(8p2 - p5)/128], "
685 "e4 = [(128p3 - p6)/4096]: 8e1 = p5 and 128e2 = p6 and "
686 "128e3 = 8p2 - p5 and 4096e4 = 128p3 - p6 and p2 >= 0 and "
687 "16e0 >= 16 + 16p6 + 15p10 and p2 <= 15 and p3 >= 0 and "
688 "p3 <= 31 and p6 >= 128p3 and p5 >= 8p2 and p10 >= 0 and "
689 "16e0 <= 15 + p0 + 15p6 + 15p10 and 16e0 >= p0 + 15p6 + 15p10 and "
690 "p10 <= 15 and p10 <= -1 + p0 - p6) }";
691 bset1
= isl_basic_set_read_from_str(ctx
, str
, -1);
692 str
= "[p0, p2, p3, p5, p6, p10] -> { [] : exists (e0 = [(p5)/8], "
693 "e1 = [(p6)/128], e2 = [(8p2 - p5)/128], "
694 "e3 = [(128p3 - p6)/4096]: 8e0 = p5 and 128e1 = p6 and "
695 "128e2 = 8p2 - p5 and 4096e3 = 128p3 - p6 and p5 >= -7 and "
696 "p2 >= 0 and 8p2 <= -1 + p0 and p2 <= 15 and p3 >= 0 and "
697 "p3 <= 31 and 128p3 <= -1 + p0 and p6 >= -127 and "
698 "p5 <= -1 + p0 and p6 <= -1 + p0 and p6 >= 128p3 and "
699 "p0 >= 1 and p5 >= 8p2 and p10 >= 0 and p10 <= 15 ) }";
700 bset2
= isl_basic_set_read_from_str(ctx
, str
, -1);
701 bset1
= isl_basic_set_gist(bset1
, bset2
);
702 assert(bset1
&& bset1
->n_div
== 0);
703 isl_basic_set_free(bset1
);
706 void test_coalesce_set(isl_ctx
*ctx
, const char *str
, int check_one
)
710 set
= isl_set_read_from_str(ctx
, str
, -1);
711 set
= isl_set_coalesce(set
);
712 set2
= isl_set_read_from_str(ctx
, str
, -1);
713 assert(isl_set_is_equal(set
, set2
));
715 assert(set
&& set
->n
== 1);
720 void test_coalesce(struct isl_ctx
*ctx
)
723 struct isl_set
*set
, *set2
;
724 struct isl_map
*map
, *map2
;
726 set
= isl_set_read_from_str(ctx
,
727 "{[x,y]: x >= 0 & x <= 10 & y >= 0 & y <= 10 or "
728 "y >= x & x >= 2 & 5 >= y }", -1);
729 set
= isl_set_coalesce(set
);
730 assert(set
&& set
->n
== 1);
733 set
= isl_set_read_from_str(ctx
,
734 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
735 "x + y >= 10 & y <= x & x + y <= 20 & y >= 0}", -1);
736 set
= isl_set_coalesce(set
);
737 assert(set
&& set
->n
== 1);
740 set
= isl_set_read_from_str(ctx
,
741 "{[x,y]: y >= 0 & 2x + y <= 30 & y <= 10 & x >= 0 or "
742 "x + y >= 10 & y <= x & x + y <= 19 & y >= 0}", -1);
743 set
= isl_set_coalesce(set
);
744 assert(set
&& set
->n
== 2);
747 set
= isl_set_read_from_str(ctx
,
748 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
749 "y >= 0 & x >= 6 & x <= 10 & y <= x}", -1);
750 set
= isl_set_coalesce(set
);
751 assert(set
&& set
->n
== 1);
754 set
= isl_set_read_from_str(ctx
,
755 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
756 "y >= 0 & x >= 7 & x <= 10 & y <= x}", -1);
757 set
= isl_set_coalesce(set
);
758 assert(set
&& set
->n
== 2);
761 set
= isl_set_read_from_str(ctx
,
762 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
763 "y >= 0 & x >= 6 & x <= 10 & y + 1 <= x}", -1);
764 set
= isl_set_coalesce(set
);
765 assert(set
&& set
->n
== 2);
768 set
= isl_set_read_from_str(ctx
,
769 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
770 "y >= 0 & x = 6 & y <= 6}", -1);
771 set
= isl_set_coalesce(set
);
772 assert(set
&& set
->n
== 1);
775 set
= isl_set_read_from_str(ctx
,
776 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
777 "y >= 0 & x = 7 & y <= 6}", -1);
778 set
= isl_set_coalesce(set
);
779 assert(set
&& set
->n
== 2);
782 set
= isl_set_read_from_str(ctx
,
783 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
784 "y >= 0 & x = 6 & y <= 5}", -1);
785 set
= isl_set_coalesce(set
);
786 assert(set
&& set
->n
== 1);
787 set2
= isl_set_read_from_str(ctx
,
788 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
789 "y >= 0 & x = 6 & y <= 5}", -1);
790 assert(isl_set_is_equal(set
, set2
));
794 set
= isl_set_read_from_str(ctx
,
795 "{[x,y]: y >= 0 & x <= 5 & y <= x or "
796 "y >= 0 & x = 6 & y <= 7}", -1);
797 set
= isl_set_coalesce(set
);
798 assert(set
&& set
->n
== 2);
801 set
= isl_set_read_from_str(ctx
,
802 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
803 set
= isl_set_coalesce(set
);
804 assert(set
&& set
->n
== 1);
805 set2
= isl_set_read_from_str(ctx
,
806 "[n] -> { [i] : i = 1 and n >= 2 or 2 <= i and i <= n }", -1);
807 assert(isl_set_is_equal(set
, set2
));
811 set
= isl_set_read_from_str(ctx
,
812 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
813 set
= isl_set_coalesce(set
);
814 set2
= isl_set_read_from_str(ctx
,
815 "{[x,y] : x >= 0 and y >= 0 or 0 <= y and y <= 5 and x = -1}", -1);
816 assert(isl_set_is_equal(set
, set2
));
820 set
= isl_set_read_from_str(ctx
,
821 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
822 "2 <= i and i <= n }", -1);
823 set
= isl_set_coalesce(set
);
824 assert(set
&& set
->n
== 1);
825 set2
= isl_set_read_from_str(ctx
,
826 "[n] -> { [i] : 1 <= i and i <= n - 1 or "
827 "2 <= i and i <= n }", -1);
828 assert(isl_set_is_equal(set
, set2
));
832 map
= isl_map_read_from_str(ctx
,
833 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
834 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
835 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
836 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
837 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
838 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
839 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
840 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
841 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
842 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
843 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
844 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
845 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
846 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
847 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
848 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
849 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
850 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
851 map
= isl_map_coalesce(map
);
852 map2
= isl_map_read_from_str(ctx
,
853 "[n] -> { [i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
854 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
855 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
856 "4e4 = -2 + o0 and i0 >= 8 + 2n and o0 >= 2 + i0 and "
857 "o0 <= 56 + 2n and o0 <= -12 + 4n and i0 <= 57 + 2n and "
858 "i0 <= -11 + 4n and o0 >= 6 + 2n and 4e0 <= i0 and "
859 "4e0 >= -3 + i0 and 4e1 <= o0 and 4e1 >= -3 + o0 and "
860 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0);"
861 "[i0] -> [o0] : exists (e0 = [(i0)/4], e1 = [(o0)/4], "
862 "e2 = [(n)/2], e3 = [(-2 + i0)/4], e4 = [(-2 + o0)/4], "
863 "e5 = [(-2n + i0)/4]: 2e2 = n and 4e3 = -2 + i0 and "
864 "4e4 = -2 + o0 and 2e0 >= 3 + n and e0 <= -4 + n and "
865 "2e0 <= 27 + n and e1 <= -4 + n and 2e1 <= 27 + n and "
866 "2e1 >= 2 + n and e1 >= 1 + e0 and i0 >= 7 + 2n and "
867 "i0 <= -11 + 4n and i0 <= 57 + 2n and 4e0 <= -2 + i0 and "
868 "4e0 >= -3 + i0 and o0 >= 6 + 2n and o0 <= -11 + 4n and "
869 "o0 <= 57 + 2n and 4e1 <= -2 + o0 and 4e1 >= -3 + o0 and "
870 "4e5 <= -2n + i0 and 4e5 >= -3 - 2n + i0 ) }", -1);
871 assert(isl_map_is_equal(map
, map2
));
875 str
= "[n, m] -> { [] -> [o0, o2, o3] : (o3 = 1 and o0 >= 1 + m and "
876 "o0 <= n + m and o2 <= m and o0 >= 2 + n and o2 >= 3) or "
877 "(o0 >= 2 + n and o0 >= 1 + m and o0 <= n + m and n >= 1 and "
878 "o3 <= -1 + o2 and o3 >= 1 - m + o2 and o3 >= 2 and o3 <= n) }";
879 map
= isl_map_read_from_str(ctx
, str
, -1);
880 map
= isl_map_coalesce(map
);
881 map2
= isl_map_read_from_str(ctx
, str
, -1);
882 assert(isl_map_is_equal(map
, map2
));
886 str
= "[M, N] -> { [i0, i1, i2, i3, i4, i5, i6] -> "
887 "[o0, o1, o2, o3, o4, o5, o6] : "
888 "(o6 <= -4 + 2M - 2N + i0 + i1 - i2 + i6 - o0 - o1 + o2 and "
889 "o3 <= -2 + i3 and o6 >= 2 + i0 + i3 + i6 - o0 - o3 and "
890 "o6 >= 2 - M + N + i3 + i4 + i6 - o3 - o4 and o0 <= -1 + i0 and "
891 "o4 >= 4 - 3M + 3N - i0 - i1 + i2 + 2i3 + i4 + o0 + o1 - o2 - 2o3 "
892 "and o6 <= -3 + 2M - 2N + i3 + i4 - i5 + i6 - o3 - o4 + o5 and "
893 "2o6 <= -5 + 5M - 5N + 2i0 + i1 - i2 - i5 + 2i6 - 2o0 - o1 + o2 + o5 "
894 "and o6 >= 2i0 + i1 + i6 - 2o0 - o1 and "
895 "3o6 <= -5 + 4M - 4N + 2i0 + i1 - i2 + 2i3 + i4 - i5 + 3i6 "
896 "- 2o0 - o1 + o2 - 2o3 - o4 + o5) or "
897 "(N >= 2 and o3 <= -1 + i3 and o0 <= -1 + i0 and "
898 "o6 >= i3 + i6 - o3 and M >= 0 and "
899 "2o6 >= 1 + i0 + i3 + 2i6 - o0 - o3 and "
900 "o6 >= 1 - M + i0 + i6 - o0 and N >= 2M and o6 >= i0 + i6 - o0) }";
901 map
= isl_map_read_from_str(ctx
, str
, -1);
902 map
= isl_map_coalesce(map
);
903 map2
= isl_map_read_from_str(ctx
, str
, -1);
904 assert(isl_map_is_equal(map
, map2
));
908 str
= "[M, N] -> { [] -> [o0] : (o0 = 0 and M >= 1 and N >= 2) or "
909 "(o0 = 0 and M >= 1 and N >= 2M and N >= 2 + M) or "
910 "(o0 = 0 and M >= 2 and N >= 3) or "
911 "(M = 0 and o0 = 0 and N >= 3) }";
912 map
= isl_map_read_from_str(ctx
, str
, -1);
913 map
= isl_map_coalesce(map
);
914 map2
= isl_map_read_from_str(ctx
, str
, -1);
915 assert(isl_map_is_equal(map
, map2
));
919 str
= "{ [i0, i1, i2, i3] : (i1 = 10i0 and i0 >= 1 and 10i0 <= 100 and "
920 "i3 <= 9 + 10 i2 and i3 >= 1 + 10i2 and i3 >= 0) or "
921 "(i1 <= 9 + 10i0 and i1 >= 1 + 10i0 and i2 >= 0 and "
922 "i0 >= 0 and i1 <= 100 and i3 <= 9 + 10i2 and i3 >= 1 + 10i2) }";
923 map
= isl_map_read_from_str(ctx
, str
, -1);
924 map
= isl_map_coalesce(map
);
925 map2
= isl_map_read_from_str(ctx
, str
, -1);
926 assert(isl_map_is_equal(map
, map2
));
930 test_coalesce_set(ctx
,
931 "[M] -> { [i1] : (i1 >= 2 and i1 <= M) or "
932 "(i1 = M and M >= 1) }", 0);
933 test_coalesce_set(ctx
,
934 "{[x,y] : x,y >= 0; [x,y] : 10 <= x <= 20 and y >= -1 }", 0);
935 test_coalesce_set(ctx
,
936 "{ [x, y] : (x >= 1 and y >= 1 and x <= 2 and y <= 2) or "
937 "(y = 3 and x = 1) }", 1);
938 test_coalesce_set(ctx
,
939 "[M] -> { [i0, i1, i2, i3, i4] : (i1 >= 3 and i4 >= 2 + i2 and "
940 "i2 >= 2 and i0 >= 2 and i3 >= 1 + i2 and i0 <= M and "
941 "i1 <= M and i3 <= M and i4 <= M) or "
942 "(i1 >= 2 and i4 >= 1 + i2 and i2 >= 2 and i0 >= 2 and "
943 "i3 >= 1 + i2 and i0 <= M and i1 <= -1 + M and i3 <= M and "
944 "i4 <= -1 + M) }", 1);
945 test_coalesce_set(ctx
,
946 "{ [x, y] : (x >= 0 and y >= 0 and x <= 10 and y <= 10) or "
947 "(x >= 1 and y >= 1 and x <= 11 and y <= 11) }", 1);
948 test_coalesce_set(ctx
,
949 "{[x,y,z] : y + 2 >= 0 and x - y + 1 >= 0 and "
950 "-x - y + 1 >= 0 and -3 <= z <= 3;"
951 "[x,y,z] : -x+z + 20 >= 0 and -x-z + 20 >= 0 and "
952 "x-z + 20 >= 0 and x+z + 20 >= 0 and -10 <= y <= 0}", 1);
953 test_coalesce_set(ctx
,
954 "{[x,y] : 0 <= x,y <= 10; [5,y]: 4 <=y <= 11}", 1);
955 test_coalesce_set(ctx
, "{[x,0] : x >= 0; [x,1] : x <= 20}", 0);
956 test_coalesce_set(ctx
,
957 "{[x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }", 1);
958 test_coalesce_set(ctx
, "{ [x, 1 - x] : 0 <= x <= 1; [0,0] }", 1);
959 test_coalesce_set(ctx
, "{ [0,0]; [i,i] : 1 <= i <= 10 }", 1);
960 test_coalesce_set(ctx
, "{ [0,0]; [i,j] : 1 <= i,j <= 10 }", 0);
961 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 1 <= i <= 10 }", 1);
962 test_coalesce_set(ctx
, "{ [0,0]; [i,2i] : 2 <= i <= 10 }", 0);
963 test_coalesce_set(ctx
, "{ [1,0]; [i,2i] : 1 <= i <= 10 }", 0);
964 test_coalesce_set(ctx
, "{ [0,1]; [i,2i] : 1 <= i <= 10 }", 0);
967 void test_closure(struct isl_ctx
*ctx
)
975 /* COCOA example 1 */
976 map
= isl_map_read_from_str(ctx
,
977 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
978 "1 <= i and i < n and 1 <= j and j < n or "
979 "i2 = i + 1 and j2 = j - 1 and "
980 "1 <= i and i < n and 2 <= j and j <= n }", -1);
981 map
= isl_map_power(map
, &exact
);
985 /* COCOA example 1 */
986 map
= isl_map_read_from_str(ctx
,
987 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 1 and j2 = j + 1 and "
988 "1 <= i and i < n and 1 <= j and j < n or "
989 "i2 = i + 1 and j2 = j - 1 and "
990 "1 <= i and i < n and 2 <= j and j <= n }", -1);
991 map
= isl_map_transitive_closure(map
, &exact
);
993 map2
= isl_map_read_from_str(ctx
,
994 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
995 "1 <= i and i < n and 1 <= j and j <= n and "
996 "2 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
997 "i2 = i + k1 + k2 and j2 = j + k1 - k2 and "
998 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1 )}", -1);
999 assert(isl_map_is_equal(map
, map2
));
1003 map
= isl_map_read_from_str(ctx
,
1004 "[n] -> { [x] -> [y] : y = x + 1 and 0 <= x and x <= n and "
1005 " 0 <= y and y <= n }", -1);
1006 map
= isl_map_transitive_closure(map
, &exact
);
1007 map2
= isl_map_read_from_str(ctx
,
1008 "[n] -> { [x] -> [y] : y > x and 0 <= x and x <= n and "
1009 " 0 <= y and y <= n }", -1);
1010 assert(isl_map_is_equal(map
, map2
));
1014 /* COCOA example 2 */
1015 map
= isl_map_read_from_str(ctx
,
1016 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j + 2 and "
1017 "1 <= i and i < n - 1 and 1 <= j and j < n - 1 or "
1018 "i2 = i + 2 and j2 = j - 2 and "
1019 "1 <= i and i < n - 1 and 3 <= j and j <= n }", -1);
1020 map
= isl_map_transitive_closure(map
, &exact
);
1022 map2
= isl_map_read_from_str(ctx
,
1023 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k : "
1024 "1 <= i and i < n - 1 and 1 <= j and j <= n and "
1025 "3 <= i2 and i2 <= n and 1 <= j2 and j2 <= n and "
1026 "i2 = i + 2 k1 + 2 k2 and j2 = j + 2 k1 - 2 k2 and "
1027 "k1 >= 0 and k2 >= 0 and k1 + k2 = k and k >= 1) }", -1);
1028 assert(isl_map_is_equal(map
, map2
));
1032 /* COCOA Fig.2 left */
1033 map
= isl_map_read_from_str(ctx
,
1034 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 2 and j2 = j and "
1035 "i <= 2 j - 3 and i <= n - 2 and j <= 2 i - 1 and "
1037 "i2 = i and j2 = j + 2 and i <= 2 j - 1 and i <= n and "
1038 "j <= 2 i - 3 and j <= n - 2 or "
1039 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1040 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1041 map
= isl_map_transitive_closure(map
, &exact
);
1045 /* COCOA Fig.2 right */
1046 map
= isl_map_read_from_str(ctx
,
1047 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1048 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1050 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1051 "j <= 2 i - 4 and j <= n - 3 or "
1052 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1053 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1054 map
= isl_map_power(map
, &exact
);
1058 /* COCOA Fig.2 right */
1059 map
= isl_map_read_from_str(ctx
,
1060 "[n] -> { [i,j] -> [i2,j2] : i2 = i + 3 and j2 = j and "
1061 "i <= 2 j - 4 and i <= n - 3 and j <= 2 i - 1 and "
1063 "i2 = i and j2 = j + 3 and i <= 2 j - 1 and i <= n and "
1064 "j <= 2 i - 4 and j <= n - 3 or "
1065 "i2 = i + 1 and j2 = j + 1 and i <= 2 j - 1 and "
1066 "i <= n - 1 and j <= 2 i - 1 and j <= n - 1 }", -1);
1067 map
= isl_map_transitive_closure(map
, &exact
);
1069 map2
= isl_map_read_from_str(ctx
,
1070 "[n] -> { [i,j] -> [i2,j2] : exists (k1,k2,k3,k : "
1071 "i <= 2 j - 1 and i <= n and j <= 2 i - 1 and "
1072 "j <= n and 3 + i + 2 j <= 3 n and "
1073 "3 + 2 i + j <= 3n and i2 <= 2 j2 -1 and i2 <= n and "
1074 "i2 <= 3 j2 - 4 and j2 <= 2 i2 -1 and j2 <= n and "
1075 "13 + 4 j2 <= 11 i2 and i2 = i + 3 k1 + k3 and "
1076 "j2 = j + 3 k2 + k3 and k1 >= 0 and k2 >= 0 and "
1077 "k3 >= 0 and k1 + k2 + k3 = k and k > 0) }", -1);
1078 assert(isl_map_is_equal(map
, map2
));
1082 /* COCOA Fig.1 right */
1083 dom
= isl_set_read_from_str(ctx
,
1084 "{ [x,y] : x >= 0 and -2 x + 3 y >= 0 and x <= 3 and "
1085 "2 x - 3 y + 3 >= 0 }", -1);
1086 right
= isl_map_read_from_str(ctx
,
1087 "{ [x,y] -> [x2,y2] : x2 = x + 1 and y2 = y }", -1);
1088 up
= isl_map_read_from_str(ctx
,
1089 "{ [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 }", -1);
1090 right
= isl_map_intersect_domain(right
, isl_set_copy(dom
));
1091 right
= isl_map_intersect_range(right
, isl_set_copy(dom
));
1092 up
= isl_map_intersect_domain(up
, isl_set_copy(dom
));
1093 up
= isl_map_intersect_range(up
, dom
);
1094 map
= isl_map_union(up
, right
);
1095 map
= isl_map_transitive_closure(map
, &exact
);
1097 map2
= isl_map_read_from_str(ctx
,
1098 "{ [0,0] -> [0,1]; [0,0] -> [1,1]; [0,1] -> [1,1]; "
1099 " [2,2] -> [3,2]; [2,2] -> [3,3]; [3,2] -> [3,3] }", -1);
1100 assert(isl_map_is_equal(map
, map2
));
1104 /* COCOA Theorem 1 counter example */
1105 map
= isl_map_read_from_str(ctx
,
1106 "{ [i,j] -> [i2,j2] : i = 0 and 0 <= j and j <= 1 and "
1107 "i2 = 1 and j2 = j or "
1108 "i = 0 and j = 0 and i2 = 0 and j2 = 1 }", -1);
1109 map
= isl_map_transitive_closure(map
, &exact
);
1113 map
= isl_map_read_from_str(ctx
,
1114 "[m,n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 2 and "
1115 "1 <= i,i2 <= n and 1 <= j,j2 <= m or "
1116 "i2 = i + 1 and 3 <= j2 - j <= 4 and "
1117 "1 <= i,i2 <= n and 1 <= j,j2 <= m }", -1);
1118 map
= isl_map_transitive_closure(map
, &exact
);
1122 /* Kelly et al 1996, fig 12 */
1123 map
= isl_map_read_from_str(ctx
,
1124 "[n] -> { [i,j] -> [i2,j2] : i2 = i and j2 = j + 1 and "
1125 "1 <= i,j,j+1 <= n or "
1126 "j = n and j2 = 1 and i2 = i + 1 and "
1127 "1 <= i,i+1 <= n }", -1);
1128 map
= isl_map_transitive_closure(map
, &exact
);
1130 map2
= isl_map_read_from_str(ctx
,
1131 "[n] -> { [i,j] -> [i2,j2] : 1 <= j < j2 <= n and "
1132 "1 <= i <= n and i = i2 or "
1133 "1 <= i < i2 <= n and 1 <= j <= n and "
1134 "1 <= j2 <= n }", -1);
1135 assert(isl_map_is_equal(map
, map2
));
1139 /* Omega's closure4 */
1140 map
= isl_map_read_from_str(ctx
,
1141 "[m,n] -> { [x,y] -> [x2,y2] : x2 = x and y2 = y + 1 and "
1142 "1 <= x,y <= 10 or "
1143 "x2 = x + 1 and y2 = y and "
1144 "1 <= x <= 20 && 5 <= y <= 15 }", -1);
1145 map
= isl_map_transitive_closure(map
, &exact
);
1149 map
= isl_map_read_from_str(ctx
,
1150 "[n] -> { [x] -> [y]: 1 <= n <= y - x <= 10 }", -1);
1151 map
= isl_map_transitive_closure(map
, &exact
);
1153 map2
= isl_map_read_from_str(ctx
,
1154 "[n] -> { [x] -> [y] : 1 <= n <= 10 and y >= n + x }", -1);
1155 assert(isl_map_is_equal(map
, map2
));
1159 str
= "[n, m] -> { [i0, i1, i2, i3] -> [o0, o1, o2, o3] : "
1160 "i3 = 1 and o0 = i0 and o1 = -1 + i1 and o2 = -1 + i2 and "
1161 "o3 = -2 + i2 and i1 <= -1 + i0 and i1 >= 1 - m + i0 and "
1162 "i1 >= 2 and i1 <= n and i2 >= 3 and i2 <= 1 + n and i2 <= m }";
1163 map
= isl_map_read_from_str(ctx
, str
, -1);
1164 map
= isl_map_transitive_closure(map
, &exact
);
1166 map2
= isl_map_read_from_str(ctx
, str
, -1);
1167 assert(isl_map_is_equal(map
, map2
));
1171 str
= "{[0] -> [1]; [2] -> [3]}";
1172 map
= isl_map_read_from_str(ctx
, str
, -1);
1173 map
= isl_map_transitive_closure(map
, &exact
);
1175 map2
= isl_map_read_from_str(ctx
, str
, -1);
1176 assert(isl_map_is_equal(map
, map2
));
1180 str
= "[n] -> { [[i0, i1, 1, 0, i0] -> [i5, 1]] -> "
1181 "[[i0, -1 + i1, 2, 0, i0] -> [-1 + i5, 2]] : "
1182 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 2 and "
1183 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1184 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1185 "[[i0, i1, 2, 0, i0] -> [i5, 1]] -> "
1186 "[[i0, i1, 1, 0, i0] -> [-1 + i5, 2]] : "
1187 "exists (e0 = [(3 - n)/3]: i5 >= 2 and i1 >= 1 and "
1188 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1189 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1190 "[[i0, i1, 1, 0, i0] -> [i5, 2]] -> "
1191 "[[i0, -1 + i1, 2, 0, i0] -> [i5, 1]] : "
1192 "exists (e0 = [(3 - n)/3]: i1 >= 2 and i5 >= 1 and "
1193 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1194 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n); "
1195 "[[i0, i1, 2, 0, i0] -> [i5, 2]] -> "
1196 "[[i0, i1, 1, 0, i0] -> [i5, 1]] : "
1197 "exists (e0 = [(3 - n)/3]: i5 >= 1 and i1 >= 1 and "
1198 "3i0 <= -1 + n and i1 <= -1 + n and i5 <= -1 + n and "
1199 "3e0 >= 1 - n and 3e0 <= 2 - n and 3i0 >= -2 + n) }";
1200 map
= isl_map_read_from_str(ctx
, str
, -1);
1201 map
= isl_map_transitive_closure(map
, NULL
);
1206 void test_lex(struct isl_ctx
*ctx
)
1211 dim
= isl_dim_alloc(ctx
, 0, 0, 0);
1212 map
= isl_map_lex_le(dim
);
1213 assert(!isl_map_is_empty(map
));
1217 void test_lexmin(struct isl_ctx
*ctx
)
1220 isl_map
*map
, *map2
;
1224 str
= "[p0, p1] -> { [] -> [] : "
1225 "exists (e0 = [(2p1)/3], e1, e2, e3 = [(3 - p1 + 3e0)/3], "
1226 "e4 = [(p1)/3], e5 = [(p1 + 3e4)/3]: "
1227 "3e0 >= -2 + 2p1 and 3e0 >= p1 and 3e3 >= 1 - p1 + 3e0 and "
1228 "3e0 <= 2p1 and 3e3 >= -2 + p1 and 3e3 <= -1 + p1 and p1 >= 3 and "
1229 "3e5 >= -2 + 2p1 and 3e5 >= p1 and 3e5 <= -1 + p1 + 3e4 and "
1230 "3e4 <= p1 and 3e4 >= -2 + p1 and e3 <= -1 + e0 and "
1231 "3e4 >= 6 - p1 + 3e1 and 3e1 >= p1 and 3e5 >= -2 + p1 + 3e4 and "
1232 "2e4 >= 3 - p1 + 2e1 and e4 <= e1 and 3e3 <= 2 - p1 + 3e0 and "
1233 "e5 >= 1 + e1 and 3e4 >= 6 - 2p1 + 3e1 and "
1234 "p0 >= 2 and p1 >= p0 and 3e2 >= p1 and 3e4 >= 6 - p1 + 3e2 and "
1235 "e2 <= e1 and e3 >= 1 and e4 <= e2) }";
1236 map
= isl_map_read_from_str(ctx
, str
, -1);
1237 map
= isl_map_lexmin(map
);
1240 str
= "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and "
1241 "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }";
1242 set
= isl_set_read_from_str(ctx
, str
, -1);
1243 set
= isl_set_lexmax(set
);
1244 str
= "[C] -> { [obj,a,b,c] : C = 8 }";
1245 set2
= isl_set_read_from_str(ctx
, str
, -1);
1246 set
= isl_set_intersect(set
, set2
);
1247 assert(!isl_set_is_empty(set
));
1250 str
= "{ [x] -> [y] : x <= y <= 10; [x] -> [5] : -8 <= x <= 8 }";
1251 map
= isl_map_read_from_str(ctx
, str
, -1);
1252 map
= isl_map_lexmin(map
);
1253 str
= "{ [x] -> [5] : 6 <= x <= 8; "
1254 "[x] -> [x] : x <= 5 or (9 <= x <= 10) }";
1255 map2
= isl_map_read_from_str(ctx
, str
, -1);
1256 assert(isl_map_is_equal(map
, map2
));
1260 str
= "{ [x] -> [y] : 4y = x or 4y = -1 + x or 4y = -2 + x }";
1261 map
= isl_map_read_from_str(ctx
, str
, -1);
1262 map2
= isl_map_copy(map
);
1263 map
= isl_map_lexmin(map
);
1264 assert(isl_map_is_equal(map
, map2
));
1268 str
= "{ [x] -> [y] : x = 4y; [x] -> [y] : x = 2y }";
1269 map
= isl_map_read_from_str(ctx
, str
, -1);
1270 map
= isl_map_lexmin(map
);
1271 str
= "{ [x] -> [y] : (4y = x and x >= 0) or "
1272 "(exists (e0 = [(x)/4], e1 = [(-2 + x)/4]: 2y = x and "
1273 "4e1 = -2 + x and 4e0 <= -1 + x and 4e0 >= -3 + x)) or "
1274 "(exists (e0 = [(x)/4]: 2y = x and 4e0 = x and x <= -4)) }";
1275 map2
= isl_map_read_from_str(ctx
, str
, -1);
1276 assert(isl_map_is_equal(map
, map2
));
1286 static int collect_must_may(__isl_take isl_map
*dep
, int must
,
1287 void *dep_user
, void *user
)
1289 struct must_may
*mm
= (struct must_may
*)user
;
1292 mm
->must
= isl_map_union(mm
->must
, dep
);
1294 mm
->may
= isl_map_union(mm
->may
, dep
);
1299 static int common_space(void *first
, void *second
)
1301 int depth
= *(int *)first
;
1305 static int map_is_equal(__isl_keep isl_map
*map
, const char *str
)
1313 map2
= isl_map_read_from_str(map
->ctx
, str
, -1);
1314 equal
= isl_map_is_equal(map
, map2
);
1320 void test_dep(struct isl_ctx
*ctx
)
1325 isl_access_info
*ai
;
1332 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1333 map
= isl_map_read_from_str(ctx
, str
, -1);
1334 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1336 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1337 map
= isl_map_read_from_str(ctx
, str
, -1);
1338 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1340 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1341 map
= isl_map_read_from_str(ctx
, str
, -1);
1342 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1344 flow
= isl_access_info_compute_flow(ai
);
1345 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1346 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1347 mm
.may
= isl_map_empty(dim
);
1349 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1351 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); "
1352 " [1,10,0] -> [2,5,0] }";
1353 assert(map_is_equal(mm
.must
, str
));
1354 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1355 assert(map_is_equal(mm
.may
, str
));
1357 isl_map_free(mm
.must
);
1358 isl_map_free(mm
.may
);
1359 isl_flow_free(flow
);
1362 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1363 map
= isl_map_read_from_str(ctx
, str
, -1);
1364 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1366 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1367 map
= isl_map_read_from_str(ctx
, str
, -1);
1368 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1370 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1371 map
= isl_map_read_from_str(ctx
, str
, -1);
1372 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1374 flow
= isl_access_info_compute_flow(ai
);
1375 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1376 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1377 mm
.may
= isl_map_empty(dim
);
1379 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1381 str
= "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10) }";
1382 assert(map_is_equal(mm
.must
, str
));
1383 str
= "{ [0,5,0] -> [2,5,0]; [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1384 assert(map_is_equal(mm
.may
, str
));
1386 isl_map_free(mm
.must
);
1387 isl_map_free(mm
.may
);
1388 isl_flow_free(flow
);
1391 str
= "{ [2,i,0] -> [i] : 0 <= i <= 10 }";
1392 map
= isl_map_read_from_str(ctx
, str
, -1);
1393 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1395 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1396 map
= isl_map_read_from_str(ctx
, str
, -1);
1397 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1399 str
= "{ [1,i,0] -> [5] : 0 <= i <= 10 }";
1400 map
= isl_map_read_from_str(ctx
, str
, -1);
1401 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1403 flow
= isl_access_info_compute_flow(ai
);
1404 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1405 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1406 mm
.may
= isl_map_empty(dim
);
1408 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1410 str
= "{ [0,i,0] -> [2,i,0] : 0 <= i <= 10; "
1411 " [1,i,0] -> [2,5,0] : 0 <= i <= 10 }";
1412 assert(map_is_equal(mm
.may
, str
));
1413 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1414 assert(map_is_equal(mm
.must
, str
));
1416 isl_map_free(mm
.must
);
1417 isl_map_free(mm
.may
);
1418 isl_flow_free(flow
);
1421 str
= "{ [0,i,2] -> [i] : 0 <= i <= 10 }";
1422 map
= isl_map_read_from_str(ctx
, str
, -1);
1423 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1425 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1426 map
= isl_map_read_from_str(ctx
, str
, -1);
1427 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1429 str
= "{ [0,i,1] -> [5] : 0 <= i <= 10 }";
1430 map
= isl_map_read_from_str(ctx
, str
, -1);
1431 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1433 flow
= isl_access_info_compute_flow(ai
);
1434 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
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] -> [0,i,2] : 0 <= i <= 10; "
1441 " [0,i,1] -> [0,5,2] : 0 <= i <= 5 }";
1442 assert(map_is_equal(mm
.may
, str
));
1443 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1444 assert(map_is_equal(mm
.must
, str
));
1446 isl_map_free(mm
.must
);
1447 isl_map_free(mm
.may
);
1448 isl_flow_free(flow
);
1451 str
= "{ [0,i,1] -> [i] : 0 <= i <= 10 }";
1452 map
= isl_map_read_from_str(ctx
, str
, -1);
1453 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 2);
1455 str
= "{ [0,i,0] -> [i] : 0 <= i <= 10 }";
1456 map
= isl_map_read_from_str(ctx
, str
, -1);
1457 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1459 str
= "{ [0,i,2] -> [5] : 0 <= i <= 10 }";
1460 map
= isl_map_read_from_str(ctx
, str
, -1);
1461 ai
= isl_access_info_add_source(ai
, map
, 0, &depth
);
1463 flow
= isl_access_info_compute_flow(ai
);
1464 dim
= isl_dim_alloc(ctx
, 0, 3, 3);
1465 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1466 mm
.may
= isl_map_empty(dim
);
1468 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1470 str
= "{ [0,i,0] -> [0,i,1] : 0 <= i <= 10; "
1471 " [0,i,2] -> [0,5,1] : 0 <= i <= 4 }";
1472 assert(map_is_equal(mm
.may
, str
));
1473 str
= "{ [i,j,k] -> [l,m,n] : 1 = 0 }";
1474 assert(map_is_equal(mm
.must
, str
));
1476 isl_map_free(mm
.must
);
1477 isl_map_free(mm
.may
);
1478 isl_flow_free(flow
);
1483 str
= "{ [1,i,0,0,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1484 map
= isl_map_read_from_str(ctx
, str
, -1);
1485 ai
= isl_access_info_alloc(map
, &depth
, &common_space
, 1);
1487 str
= "{ [0,i,0,j,0] -> [i,j] : 0 <= i <= 10 and 0 <= j <= 10 }";
1488 map
= isl_map_read_from_str(ctx
, str
, -1);
1489 ai
= isl_access_info_add_source(ai
, map
, 1, &depth
);
1491 flow
= isl_access_info_compute_flow(ai
);
1492 dim
= isl_dim_alloc(ctx
, 0, 5, 5);
1493 mm
.must
= isl_map_empty(isl_dim_copy(dim
));
1494 mm
.may
= isl_map_empty(dim
);
1496 isl_flow_foreach(flow
, collect_must_may
, &mm
);
1498 str
= "{ [0,i,0,j,0] -> [1,i,0,0,0] : 0 <= i,j <= 10 }";
1499 assert(map_is_equal(mm
.must
, str
));
1500 str
= "{ [0,0,0,0,0] -> [0,0,0,0,0] : 1 = 0 }";
1501 assert(map_is_equal(mm
.may
, str
));
1503 isl_map_free(mm
.must
);
1504 isl_map_free(mm
.may
);
1505 isl_flow_free(flow
);
1508 void test_sv(struct isl_ctx
*ctx
)
1513 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 9 }";
1514 map
= isl_map_read_from_str(ctx
, str
, -1);
1515 assert(isl_map_is_single_valued(map
));
1518 str
= "[N] -> { [i] -> [f] : 0 <= i <= N and 0 <= i - 10 f <= 10 }";
1519 map
= isl_map_read_from_str(ctx
, str
, -1);
1520 assert(!isl_map_is_single_valued(map
));
1524 void test_bijective_case(struct isl_ctx
*ctx
, const char *str
, int bijective
)
1528 map
= isl_map_read_from_str(ctx
, str
, -1);
1530 assert(isl_map_is_bijective(map
));
1532 assert(!isl_map_is_bijective(map
));
1536 void test_bijective(struct isl_ctx
*ctx
)
1538 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i]}", 0);
1539 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=i}", 1);
1540 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=0}", 1);
1541 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i] : j=N}", 1);
1542 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [j,i]}", 1);
1543 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i+j]}", 0);
1544 test_bijective_case(ctx
, "[N,M]->{[i,j] -> []}", 0);
1545 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,j,N]}", 1);
1546 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i]}", 0);
1547 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [i,i]}", 0);
1548 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,i]}", 0);
1549 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [2i,j]}", 1);
1550 test_bijective_case(ctx
, "[N,M]->{[i,j] -> [x,y] : 2x=i & y =j}", 1);
1553 void test_pwqp(struct isl_ctx
*ctx
)
1557 isl_pw_qpolynomial
*pwqp1
, *pwqp2
;
1559 str
= "{ [i,j,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1560 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1562 pwqp1
= isl_pw_qpolynomial_move_dims(pwqp1
, isl_dim_param
, 0,
1565 str
= "[j] -> { [i,k] -> 1 + 9 * [i/5] + 7 * [j/11] + 4 * [k/13] }";
1566 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1568 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1570 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1572 isl_pw_qpolynomial_free(pwqp1
);
1574 str
= "{ [i] -> i }";
1575 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1576 str
= "{ [k] : exists a : k = 2a }";
1577 set
= isl_set_read_from_str(ctx
, str
, 0);
1578 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1579 str
= "{ [i] -> i }";
1580 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1582 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1584 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1586 isl_pw_qpolynomial_free(pwqp1
);
1588 str
= "{ [i] -> i + [ (i + [i/3])/2 ] }";
1589 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1591 set
= isl_set_read_from_str(ctx
, str
, 0);
1592 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1593 str
= "{ [i] -> 16 }";
1594 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1596 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1598 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1600 isl_pw_qpolynomial_free(pwqp1
);
1602 str
= "{ [i] -> ([(i)/2]) }";
1603 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1604 str
= "{ [k] : exists a : k = 2a+1 }";
1605 set
= isl_set_read_from_str(ctx
, str
, 0);
1606 pwqp1
= isl_pw_qpolynomial_gist(pwqp1
, set
);
1607 str
= "{ [i] -> -1/2 + 1/2 * i }";
1608 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1610 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1612 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1614 isl_pw_qpolynomial_free(pwqp1
);
1616 str
= "{ [i] -> ([([i/2] + [i/2])/5]) }";
1617 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1618 str
= "{ [i] -> ([(2 * [i/2])/5]) }";
1619 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1621 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1623 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1625 isl_pw_qpolynomial_free(pwqp1
);
1627 str
= "{ [x] -> ([x/2] + [(x+1)/2]) }";
1628 pwqp1
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1629 str
= "{ [x] -> x }";
1630 pwqp2
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1632 pwqp1
= isl_pw_qpolynomial_sub(pwqp1
, pwqp2
);
1634 assert(isl_pw_qpolynomial_is_zero(pwqp1
));
1636 isl_pw_qpolynomial_free(pwqp1
);
1639 void test_split_periods(isl_ctx
*ctx
)
1642 isl_pw_qpolynomial
*pwqp
;
1644 str
= "{ [U,V] -> 1/3 * U + 2/3 * V - [(U + 2V)/3] + [U/2] : "
1645 "U + 2V + 3 >= 0 and - U -2V >= 0 and - U + 10 >= 0 and "
1646 "U >= 0; [U,V] -> U^2 : U >= 100 }";
1647 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1649 pwqp
= isl_pw_qpolynomial_split_periods(pwqp
, 2);
1652 isl_pw_qpolynomial_free(pwqp
);
1655 void test_union(isl_ctx
*ctx
)
1658 isl_union_set
*uset1
, *uset2
;
1659 isl_union_map
*umap1
, *umap2
;
1661 str
= "{ [i] : 0 <= i <= 1 }";
1662 uset1
= isl_union_set_read_from_str(ctx
, str
);
1663 str
= "{ [1] -> [0] }";
1664 umap1
= isl_union_map_read_from_str(ctx
, str
);
1666 umap2
= isl_union_set_lex_gt_union_set(isl_union_set_copy(uset1
), uset1
);
1667 assert(isl_union_map_is_equal(umap1
, umap2
));
1669 isl_union_map_free(umap1
);
1670 isl_union_map_free(umap2
);
1672 str
= "{ A[i] -> B[i]; B[i] -> C[i]; A[0] -> C[1] }";
1673 umap1
= isl_union_map_read_from_str(ctx
, str
);
1674 str
= "{ A[i]; B[i] }";
1675 uset1
= isl_union_set_read_from_str(ctx
, str
);
1677 uset2
= isl_union_map_domain(umap1
);
1679 assert(isl_union_set_is_equal(uset1
, uset2
));
1681 isl_union_set_free(uset1
);
1682 isl_union_set_free(uset2
);
1685 void test_bound(isl_ctx
*ctx
)
1688 isl_pw_qpolynomial
*pwqp
;
1689 isl_pw_qpolynomial_fold
*pwf
;
1691 str
= "{ [[a, b, c, d] -> [e]] -> 0 }";
1692 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1693 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1694 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 4);
1695 isl_pw_qpolynomial_fold_free(pwf
);
1697 str
= "{ [[x]->[x]] -> 1 : exists a : x = 2 a }";
1698 pwqp
= isl_pw_qpolynomial_read_from_str(ctx
, str
);
1699 pwf
= isl_pw_qpolynomial_bound(pwqp
, isl_fold_max
, NULL
);
1700 assert(isl_pw_qpolynomial_fold_dim(pwf
, isl_dim_set
) == 1);
1701 isl_pw_qpolynomial_fold_free(pwf
);
1704 void test_lift(isl_ctx
*ctx
)
1707 isl_basic_map
*bmap
;
1708 isl_basic_set
*bset
;
1710 str
= "{ [i0] : exists e0 : i0 = 4e0 }";
1711 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1712 bset
= isl_basic_set_lift(bset
);
1713 bmap
= isl_basic_map_from_range(bset
);
1714 bset
= isl_basic_map_domain(bmap
);
1715 isl_basic_set_free(bset
);
1718 void test_subset(isl_ctx
*ctx
)
1721 isl_set
*set1
, *set2
;
1723 str
= "{ [112, 0] }";
1724 set1
= isl_set_read_from_str(ctx
, str
, 0);
1725 str
= "{ [i0, i1] : exists (e0 = [(i0 - i1)/16], e1: "
1726 "16e0 <= i0 - i1 and 16e0 >= -15 + i0 - i1 and "
1727 "16e1 <= i1 and 16e0 >= -i1 and 16e1 >= -i0 + i1) }";
1728 set2
= isl_set_read_from_str(ctx
, str
, 0);
1729 assert(isl_set_is_subset(set1
, set2
));
1734 void test_factorize(isl_ctx
*ctx
)
1737 isl_basic_set
*bset
;
1740 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7] : 3i5 <= 2 - 2i0 and "
1741 "i0 >= -2 and i6 >= 1 + i3 and i7 >= 0 and 3i5 >= -2i0 and "
1742 "2i4 <= i2 and i6 >= 1 + 2i0 + 3i1 and i4 <= -1 and "
1743 "i6 >= 1 + 2i0 + 3i5 and i6 <= 2 + 2i0 + 3i5 and "
1744 "3i5 <= 2 - 2i0 - i2 + 3i4 and i6 <= 2 + 2i0 + 3i1 and "
1745 "i0 <= -1 and i7 <= i2 + i3 - 3i4 - i6 and "
1746 "3i5 >= -2i0 - i2 + 3i4 }";
1747 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1748 f
= isl_basic_set_factorizer(bset
);
1750 isl_basic_set_free(bset
);
1751 isl_factorizer_free(f
);
1753 str
= "{ [i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10, i11, i12] : "
1754 "i12 <= 2 + i0 - i11 and 2i8 >= -i4 and i11 >= i1 and "
1755 "3i5 <= -i2 and 2i11 >= -i4 - 2i7 and i11 <= 3 + i0 + 3i9 and "
1756 "i11 <= -i4 - 2i7 and i12 >= -i10 and i2 >= -2 and "
1757 "i11 >= i1 + 3i10 and i11 >= 1 + i0 + 3i9 and "
1758 "i11 <= 1 - i4 - 2i8 and 6i6 <= 6 - i2 and 3i6 >= 1 - i2 and "
1759 "i11 <= 2 + i1 and i12 <= i4 + i11 and i12 >= i0 - i11 and "
1760 "3i5 >= -2 - i2 and i12 >= -1 + i4 + i11 and 3i3 <= 3 - i2 and "
1761 "9i6 <= 11 - i2 + 6i5 and 3i3 >= 1 - i2 and "
1762 "9i6 <= 5 - i2 + 6i3 and i12 <= -1 and i2 <= 0 }";
1763 bset
= isl_basic_set_read_from_str(ctx
, str
, 0);
1764 f
= isl_basic_set_factorizer(bset
);
1766 isl_basic_set_free(bset
);
1767 isl_factorizer_free(f
);
1772 struct isl_ctx
*ctx
;
1774 srcdir
= getenv("srcdir");
1777 ctx
= isl_ctx_alloc();
1778 test_factorize(ctx
);
1783 test_split_periods(ctx
);
1788 test_bijective(ctx
);
1792 test_construction(ctx
);
1795 test_application(ctx
);
1796 test_affine_hull(ctx
);
1797 test_convex_hull(ctx
);