rename "omega" transitive closure to "box" transitive closure
[isl.git] / isl_output.c
blob7df6bcbd684bfb50c550a2fe6828062696d60259
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
3 * Copyright 2010 INRIA Saclay
5 * Use of this software is governed by the GNU LGPLv2.1 license
7 * Written by Sven Verdoolaege, K.U.Leuven, Departement
8 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
9 * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
10 * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France
13 #include <stdlib.h>
14 #include <string.h>
15 #include <isl/set.h>
16 #include <isl/seq.h>
17 #include <isl_polynomial_private.h>
18 #include <isl_printer_private.h>
19 #include <isl_dim_private.h>
20 #include <isl_map_private.h>
21 #include <isl_mat_private.h>
22 #include <isl/union_map.h>
24 static const char *s_to[2] = { " -> ", " \\to " };
25 static const char *s_and[2] = { " and ", " \\wedge " };
26 static const char *s_or[2] = { " or ", " \\vee " };
27 static const char *s_le[2] = { "<=", "\\le" };
28 static const char *s_ge[2] = { ">=", "\\ge" };
29 static const char *s_open_set[2] = { "{ ", "\\{\\, " };
30 static const char *s_close_set[2] = { " }", " \\,\\}" };
31 static const char *s_open_list[2] = { "[", "(" };
32 static const char *s_close_list[2] = { "]", ")" };
33 static const char *s_such_that[2] = { " : ", " \\mid " };
34 static const char *s_open_exists[2] = { "exists (", "\\exists \\, " };
35 static const char *s_close_exists[2] = { ")", "" };
36 static const char *s_div_prefix[2] = { "e", "\\alpha_" };
37 static const char *s_param_prefix[2] = { "p", "p_" };
38 static const char *s_input_prefix[2] = { "i", "i_" };
39 static const char *s_output_prefix[2] = { "o", "o_" };
41 static __isl_give isl_printer *print_constraint_polylib(
42 struct isl_basic_map *bmap, int ineq, int n, __isl_take isl_printer *p)
44 int i;
45 unsigned n_in = isl_basic_map_dim(bmap, isl_dim_in);
46 unsigned n_out = isl_basic_map_dim(bmap, isl_dim_out);
47 unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param);
48 isl_int *c = ineq ? bmap->ineq[n] : bmap->eq[n];
50 p = isl_printer_start_line(p);
51 p = isl_printer_print_int(p, ineq);
52 for (i = 0; i < n_out; ++i) {
53 p = isl_printer_print_str(p, " ");
54 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+i]);
56 for (i = 0; i < n_in; ++i) {
57 p = isl_printer_print_str(p, " ");
58 p = isl_printer_print_isl_int(p, c[1+nparam+i]);
60 for (i = 0; i < bmap->n_div; ++i) {
61 p = isl_printer_print_str(p, " ");
62 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+n_out+i]);
64 for (i = 0; i < nparam; ++i) {
65 p = isl_printer_print_str(p, " ");
66 p = isl_printer_print_isl_int(p, c[1+i]);
68 p = isl_printer_print_str(p, " ");
69 p = isl_printer_print_isl_int(p, c[0]);
70 p = isl_printer_end_line(p);
71 return p;
74 static __isl_give isl_printer *print_constraints_polylib(
75 struct isl_basic_map *bmap, __isl_take isl_printer *p)
77 int i;
79 p = isl_printer_set_isl_int_width(p, 5);
81 for (i = 0; i < bmap->n_eq; ++i)
82 p = print_constraint_polylib(bmap, 0, i, p);
83 for (i = 0; i < bmap->n_ineq; ++i)
84 p = print_constraint_polylib(bmap, 1, i, p);
86 return p;
89 static __isl_give isl_printer *bset_print_constraints_polylib(
90 struct isl_basic_set *bset, __isl_take isl_printer *p)
92 return print_constraints_polylib((struct isl_basic_map *)bset, p);
95 static __isl_give isl_printer *isl_basic_map_print_polylib(
96 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int ext)
98 unsigned total = isl_basic_map_total_dim(bmap);
99 p = isl_printer_start_line(p);
100 p = isl_printer_print_int(p, bmap->n_eq + bmap->n_ineq);
101 p = isl_printer_print_str(p, " ");
102 p = isl_printer_print_int(p, 1 + total + 1);
103 if (ext) {
104 p = isl_printer_print_str(p, " ");
105 p = isl_printer_print_int(p,
106 isl_basic_map_dim(bmap, isl_dim_out));
107 p = isl_printer_print_str(p, " ");
108 p = isl_printer_print_int(p,
109 isl_basic_map_dim(bmap, isl_dim_in));
110 p = isl_printer_print_str(p, " ");
111 p = isl_printer_print_int(p,
112 isl_basic_map_dim(bmap, isl_dim_div));
113 p = isl_printer_print_str(p, " ");
114 p = isl_printer_print_int(p,
115 isl_basic_map_dim(bmap, isl_dim_param));
117 p = isl_printer_end_line(p);
118 return print_constraints_polylib(bmap, p);
121 static __isl_give isl_printer *isl_basic_set_print_polylib(
122 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int ext)
124 return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p, ext);
127 static __isl_give isl_printer *isl_map_print_polylib(__isl_keep isl_map *map,
128 __isl_take isl_printer *p, int ext)
130 int i;
132 p = isl_printer_start_line(p);
133 p = isl_printer_print_int(p, map->n);
134 p = isl_printer_end_line(p);
135 for (i = 0; i < map->n; ++i) {
136 p = isl_printer_start_line(p);
137 p = isl_printer_end_line(p);
138 p = isl_basic_map_print_polylib(map->p[i], p, ext);
140 return p;
143 static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
144 __isl_take isl_printer *p, int ext)
146 return isl_map_print_polylib((struct isl_map *)set, p, ext);
149 static int count_same_name(__isl_keep isl_dim *dim,
150 enum isl_dim_type type, unsigned pos, const char *name)
152 enum isl_dim_type t;
153 unsigned p, s;
154 int count = 0;
156 for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) {
157 s = t == type ? pos : isl_dim_size(dim, t);
158 for (p = 0; p < s; ++p) {
159 const char *n = isl_dim_get_name(dim, t, p);
160 if (n && !strcmp(n, name))
161 count++;
164 return count;
167 static __isl_give isl_printer *print_name(__isl_keep isl_dim *dim,
168 __isl_take isl_printer *p, enum isl_dim_type type, unsigned pos,
169 int set, int latex)
171 const char *name;
172 char buffer[20];
173 int primes;
175 name = type == isl_dim_div ? NULL : isl_dim_get_name(dim, type, pos);
177 if (!name) {
178 const char *prefix;
179 if (type == isl_dim_param)
180 prefix = s_param_prefix[latex];
181 else if (type == isl_dim_div)
182 prefix = s_div_prefix[latex];
183 else if (set || type == isl_dim_in)
184 prefix = s_input_prefix[latex];
185 else
186 prefix = s_output_prefix[latex];
187 snprintf(buffer, sizeof(buffer), "%s%d", prefix, pos);
188 name = buffer;
190 primes = count_same_name(dim, name == buffer ? isl_dim_div : type,
191 pos, name);
192 p = isl_printer_print_str(p, name);
193 while (primes-- > 0)
194 p = isl_printer_print_str(p, "'");
195 return p;
198 static enum isl_dim_type pos2type(__isl_keep isl_dim *dim, unsigned *pos)
200 enum isl_dim_type type;
201 unsigned n_in = isl_dim_size(dim, isl_dim_in);
202 unsigned n_out = isl_dim_size(dim, isl_dim_out);
203 unsigned nparam = isl_dim_size(dim, isl_dim_param);
205 if (*pos < 1 + nparam) {
206 type = isl_dim_param;
207 *pos -= 1;
208 } else if (*pos < 1 + nparam + n_in) {
209 type = isl_dim_in;
210 *pos -= 1 + nparam;
211 } else if (*pos < 1 + nparam + n_in + n_out) {
212 type = isl_dim_out;
213 *pos -= 1 + nparam + n_in;
214 } else {
215 type = isl_dim_div;
216 *pos -= 1 + nparam + n_in + n_out;
219 return type;
222 static __isl_give isl_printer *print_div(__isl_keep isl_dim *dim,
223 __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p);
225 static __isl_give isl_printer *print_term(__isl_keep isl_dim *dim,
226 __isl_keep isl_mat *div,
227 isl_int c, unsigned pos, __isl_take isl_printer *p, int set, int latex)
229 enum isl_dim_type type;
230 int print_div_def;
232 if (pos == 0)
233 return isl_printer_print_isl_int(p, c);
235 type = pos2type(dim, &pos);
236 print_div_def = type == isl_dim_div && div &&
237 !isl_int_is_zero(div->row[pos][0]);
239 if (isl_int_is_one(c))
241 else if (isl_int_is_negone(c))
242 p = isl_printer_print_str(p, "-");
243 else {
244 p = isl_printer_print_isl_int(p, c);
245 if (p->output_format == ISL_FORMAT_C || print_div_def)
246 p = isl_printer_print_str(p, "*");
248 if (print_div_def)
249 p = print_div(dim, div, pos, p);
250 else
251 p = print_name(dim, p, type, pos, set, latex);
252 return p;
255 static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_dim *dim,
256 __isl_keep isl_mat *div,
257 __isl_take isl_printer *p, isl_int *c, int len, int set)
259 int i;
260 int first;
262 for (i = 0, first = 1; i < len; ++i) {
263 int flip = 0;
264 if (isl_int_is_zero(c[i]))
265 continue;
266 if (!first) {
267 if (isl_int_is_neg(c[i])) {
268 flip = 1;
269 isl_int_neg(c[i], c[i]);
270 p = isl_printer_print_str(p, " - ");
271 } else
272 p = isl_printer_print_str(p, " + ");
274 first = 0;
275 p = print_term(dim, div, c[i], i, p, set, 0);
276 if (flip)
277 isl_int_neg(c[i], c[i]);
279 if (first)
280 p = isl_printer_print_str(p, "0");
281 return p;
284 static __isl_give isl_printer *print_affine(__isl_keep isl_basic_map *bmap,
285 __isl_keep isl_dim *dim, __isl_take isl_printer *p, isl_int *c, int set)
287 unsigned len = 1 + isl_basic_map_total_dim(bmap);
288 return print_affine_of_len(dim, NULL, p, c, len, set);
291 static int defining_equality(__isl_keep isl_basic_map *eq,
292 __isl_keep isl_dim *dim, enum isl_dim_type type, int pos)
294 int i;
295 unsigned total;
297 if (!eq)
298 return -1;
300 pos += isl_dim_offset(dim, type);
301 total = isl_basic_map_total_dim(eq);
303 for (i = 0; i < eq->n_eq; ++i) {
304 if (isl_seq_last_non_zero(eq->eq[i] + 1, total) != pos)
305 continue;
306 if (isl_int_is_one(eq->eq[i][1 + pos]))
307 isl_seq_neg(eq->eq[i], eq->eq[i], 1 + total);
308 return i;
311 return -1;
314 /* offset is the offset of local_dim inside global_type of global_dim.
316 static __isl_give isl_printer *print_nested_var_list(__isl_take isl_printer *p,
317 __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
318 __isl_keep isl_dim *local_dim, enum isl_dim_type local_type,
319 int set, int latex, __isl_keep isl_basic_map *eq, int offset)
321 int i, j;
323 if (global_dim != local_dim && local_type == isl_dim_out)
324 offset += local_dim->n_in;
326 for (i = 0; i < isl_dim_size(local_dim, local_type); ++i) {
327 if (i)
328 p = isl_printer_print_str(p, ", ");
329 j = defining_equality(eq, global_dim, global_type, offset + i);
330 if (j >= 0) {
331 int pos = 1 + isl_dim_offset(global_dim, global_type)
332 + offset + i;
333 p = print_affine_of_len(eq->dim, NULL,
334 p, eq->eq[j], pos, set);
335 } else {
336 p = print_name(global_dim, p, global_type, offset + i,
337 set, latex);
340 return p;
343 static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
344 __isl_take isl_printer *p, enum isl_dim_type type,
345 int set, int latex, __isl_keep isl_basic_map *eq)
347 return print_nested_var_list(p, dim, type, dim, type, set, latex, eq, 0);
350 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
351 __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
352 __isl_keep isl_dim *local_dim,
353 int set, int latex, __isl_keep isl_basic_map *eq, int offset);
355 static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p,
356 __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
357 __isl_keep isl_dim *local_dim, enum isl_dim_type local_type,
358 int set, int latex, __isl_keep isl_basic_map *eq, int offset)
360 const char *name = NULL;
361 unsigned n = isl_dim_size(local_dim, local_type);
362 if ((local_type == isl_dim_in || local_type == isl_dim_out)) {
363 name = isl_dim_get_tuple_name(local_dim, local_type);
364 if (name) {
365 if (latex)
366 p = isl_printer_print_str(p, "\\mathrm{");
367 p = isl_printer_print_str(p, name);
368 if (latex)
369 p = isl_printer_print_str(p, "}");
372 if (!latex || n != 1 || name)
373 p = isl_printer_print_str(p, s_open_list[latex]);
374 if ((local_type == isl_dim_in || local_type == isl_dim_out) &&
375 local_dim->nested[local_type - isl_dim_in]) {
376 if (global_dim != local_dim && local_type == isl_dim_out)
377 offset += local_dim->n_in;
378 p = print_nested_map_dim(p, global_dim, global_type,
379 local_dim->nested[local_type - isl_dim_in],
380 set, latex, eq, offset);
381 } else
382 p = print_nested_var_list(p, global_dim, global_type,
383 local_dim, local_type, set, latex, eq, offset);
384 if (!latex || n != 1 || name)
385 p = isl_printer_print_str(p, s_close_list[latex]);
386 return p;
389 static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
390 __isl_take isl_printer *p, enum isl_dim_type type,
391 int set, int latex, __isl_keep isl_basic_map *eq)
393 return print_nested_tuple(p, dim, type, dim, type, set, latex, eq, 0);
396 static __isl_give isl_printer *print_nested_map_dim(__isl_take isl_printer *p,
397 __isl_keep isl_dim *global_dim, enum isl_dim_type global_type,
398 __isl_keep isl_dim *local_dim,
399 int set, int latex, __isl_keep isl_basic_map *eq, int offset)
401 p = print_nested_tuple(p, global_dim, global_type,
402 local_dim, isl_dim_in, set, latex, eq, offset);
403 p = isl_printer_print_str(p, s_to[latex]);
404 p = print_nested_tuple(p, global_dim, global_type,
405 local_dim, isl_dim_out, set, latex, eq, offset);
407 return p;
410 static __isl_give isl_printer *print_dim(__isl_keep isl_dim *dim,
411 __isl_take isl_printer *p, int set, int latex,
412 __isl_keep isl_basic_map *eq)
414 if (set)
415 p = print_tuple(dim, p, isl_dim_set, 1, latex, eq);
416 else {
417 p = print_tuple(dim, p, isl_dim_in, 0, latex, eq);
418 p = isl_printer_print_str(p, s_to[latex]);
419 p = print_tuple(dim, p, isl_dim_out, 0, latex, eq);
422 return p;
425 static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_dim *dim,
426 __isl_take isl_printer *p)
428 if (isl_dim_size(dim, isl_dim_param) == 0)
429 return p;
431 p = isl_printer_start_line(p);
432 p = isl_printer_print_str(p, "symbolic ");
433 p = print_var_list(dim, p, isl_dim_param, 0, 0, NULL);
434 p = isl_printer_print_str(p, ";");
435 p = isl_printer_end_line(p);
436 return p;
439 static __isl_give isl_printer *print_constraint(struct isl_basic_map *bmap,
440 __isl_keep isl_dim *dim, __isl_take isl_printer *p,
441 isl_int *c, int last, const char *op, int first_constraint, int set,
442 int latex)
444 if (!first_constraint)
445 p = isl_printer_print_str(p, s_and[latex]);
447 isl_int_abs(c[last], c[last]);
449 p = print_term(dim, NULL, c[last], last, p, set, latex);
451 p = isl_printer_print_str(p, " ");
452 p = isl_printer_print_str(p, op);
453 p = isl_printer_print_str(p, " ");
455 isl_int_set_si(c[last], 0);
456 p = print_affine(bmap, dim, p, c, set);
458 return p;
461 static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
462 __isl_keep isl_dim *dim, __isl_take isl_printer *p, int set, int latex)
464 int i;
465 struct isl_vec *c;
466 unsigned total = isl_basic_map_total_dim(bmap);
468 c = isl_vec_alloc(bmap->ctx, 1 + total);
469 if (!c)
470 goto error;
472 for (i = bmap->n_eq - 1; i >= 0; --i) {
473 int l = isl_seq_last_non_zero(bmap->eq[i], 1 + total);
474 isl_assert(bmap->ctx, l >= 0, goto error);
475 if (isl_int_is_neg(bmap->eq[i][l]))
476 isl_seq_cpy(c->el, bmap->eq[i], 1 + total);
477 else
478 isl_seq_neg(c->el, bmap->eq[i], 1 + total);
479 p = print_constraint(bmap, dim, p, c->el, l,
480 "=", i == bmap->n_eq - 1, set, latex);
482 for (i = 0; i < bmap->n_ineq; ++i) {
483 int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total);
484 int s;
485 const char *op;
486 if (l < 0)
487 continue;
488 s = isl_int_sgn(bmap->ineq[i][l]);
489 if (s < 0)
490 isl_seq_cpy(c->el, bmap->ineq[i], 1 + total);
491 else
492 isl_seq_neg(c->el, bmap->ineq[i], 1 + total);
493 op = s < 0 ? s_le[latex] : s_ge[latex];
494 p = print_constraint(bmap, dim, p, c->el, l,
495 op, !bmap->n_eq && !i, set, latex);
498 isl_vec_free(c);
500 return p;
501 error:
502 isl_vec_free(c);
503 isl_printer_free(p);
504 return NULL;
507 static __isl_give isl_printer *print_omega_constraints(
508 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int set)
510 if (bmap->n_eq + bmap->n_ineq == 0)
511 return p;
513 p = isl_printer_print_str(p, ": ");
514 if (bmap->n_div > 0) {
515 int i;
516 p = isl_printer_print_str(p, "exists (");
517 for (i = 0; i < bmap->n_div; ++i) {
518 if (i)
519 p = isl_printer_print_str(p, ", ");
520 p = print_name(bmap->dim, p, isl_dim_div, i, 0, 0);
522 p = isl_printer_print_str(p, ": ");
524 p = print_constraints(bmap, bmap->dim, p, set, 0);
525 if (bmap->n_div > 0)
526 p = isl_printer_print_str(p, ")");
527 return p;
530 static __isl_give isl_printer *basic_map_print_omega(
531 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
533 p = isl_printer_print_str(p, "{ [");
534 p = print_var_list(bmap->dim, p, isl_dim_in, 0, 0, NULL);
535 p = isl_printer_print_str(p, "] -> [");
536 p = print_var_list(bmap->dim, p, isl_dim_out, 0, 0, NULL);
537 p = isl_printer_print_str(p, "] ");
538 p = print_omega_constraints(bmap, p, 0);
539 p = isl_printer_print_str(p, " }");
540 return p;
543 static __isl_give isl_printer *isl_basic_map_print_omega(
544 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
546 p = print_omega_parameters(bmap->dim, p);
548 p = isl_printer_start_line(p);
549 p = basic_map_print_omega(bmap, p);
550 p = isl_printer_end_line(p);
551 return p;
554 static __isl_give isl_printer *basic_set_print_omega(
555 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
557 p = isl_printer_print_str(p, "{ [");
558 p = print_var_list(bset->dim, p, isl_dim_set, 1, 0, NULL);
559 p = isl_printer_print_str(p, "] ");
560 p = print_omega_constraints((isl_basic_map *)bset, p, 1);
561 p = isl_printer_print_str(p, " }");
562 return p;
565 static __isl_give isl_printer *isl_basic_set_print_omega(
566 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
568 p = print_omega_parameters(bset->dim, p);
570 p = isl_printer_start_line(p);
571 p = basic_set_print_omega(bset, p);
572 p = isl_printer_end_line(p);
573 return p;
576 static __isl_give isl_printer *isl_map_print_omega(__isl_keep isl_map *map,
577 __isl_take isl_printer *p)
579 int i;
581 p = print_omega_parameters(map->dim, p);
583 p = isl_printer_start_line(p);
584 for (i = 0; i < map->n; ++i) {
585 if (i)
586 p = isl_printer_print_str(p, " union ");
587 p = basic_map_print_omega(map->p[i], p);
589 p = isl_printer_end_line(p);
590 return p;
593 static __isl_give isl_printer *isl_set_print_omega(__isl_keep isl_set *set,
594 __isl_take isl_printer *p)
596 int i;
598 p = print_omega_parameters(set->dim, p);
600 p = isl_printer_start_line(p);
601 for (i = 0; i < set->n; ++i) {
602 if (i)
603 p = isl_printer_print_str(p, " union ");
604 p = basic_set_print_omega(set->p[i], p);
606 p = isl_printer_end_line(p);
607 return p;
610 static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
611 __isl_keep isl_dim *dim, __isl_take isl_printer *p, int set, int latex)
613 if (bmap->n_div > 0) {
614 int i;
615 p = isl_printer_print_str(p, s_open_exists[latex]);
616 for (i = 0; i < bmap->n_div; ++i) {
617 if (i)
618 p = isl_printer_print_str(p, ", ");
619 p = print_name(dim, p, isl_dim_div, i, 0, latex);
620 if (latex || isl_int_is_zero(bmap->div[i][0]))
621 continue;
622 p = isl_printer_print_str(p, " = [(");
623 p = print_affine(bmap, dim, p, bmap->div[i] + 1, set);
624 p = isl_printer_print_str(p, ")/");
625 p = isl_printer_print_isl_int(p, bmap->div[i][0]);
626 p = isl_printer_print_str(p, "]");
628 p = isl_printer_print_str(p, ": ");
631 p = print_constraints(bmap, dim, p, set, latex);
633 if (bmap->n_div > 0)
634 p = isl_printer_print_str(p, s_close_exists[latex]);
635 return p;
638 static __isl_give isl_printer *isl_basic_map_print_isl(
639 __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int latex)
641 int i;
643 p = isl_printer_start_line(p);
644 if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
645 p = print_tuple(bmap->dim, p, isl_dim_param, 0, latex, NULL);
646 p = isl_printer_print_str(p, " -> ");
648 p = isl_printer_print_str(p, "{ ");
649 p = print_dim(bmap->dim, p, 0, latex, NULL);
650 p = isl_printer_print_str(p, " : ");
651 p = print_disjunct(bmap, bmap->dim, p, 0, latex);
652 p = isl_printer_print_str(p, " }");
653 return p;
656 static __isl_give isl_printer *isl_basic_set_print_isl(
657 __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int latex)
659 int i;
661 p = isl_printer_start_line(p);
662 if (isl_basic_set_dim(bset, isl_dim_param) > 0) {
663 p = print_tuple(bset->dim, p, isl_dim_param, 0, latex, NULL);
664 p = isl_printer_print_str(p, " -> ");
666 p = isl_printer_print_str(p, "{ ");
667 p = print_dim(bset->dim, p, 1, latex, NULL);
668 p = isl_printer_print_str(p, " : ");
669 p = print_disjunct((isl_basic_map *)bset, bset->dim, p, 1, latex);
670 p = isl_printer_print_str(p, " }");
671 return p;
674 static __isl_give isl_printer *print_disjuncts(__isl_keep isl_map *map,
675 __isl_take isl_printer *p, int set, int latex)
677 int i;
679 if (isl_map_fast_is_universe(map))
680 return p;
682 p = isl_printer_print_str(p, s_such_that[latex]);
683 if (map->n == 0)
684 p = isl_printer_print_str(p, "1 = 0");
685 for (i = 0; i < map->n; ++i) {
686 if (i)
687 p = isl_printer_print_str(p, s_or[latex]);
688 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
689 p = isl_printer_print_str(p, "(");
690 p = print_disjunct(map->p[i], map->dim, p, set, latex);
691 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
692 p = isl_printer_print_str(p, ")");
694 return p;
697 struct isl_aff_split {
698 isl_basic_map *aff;
699 isl_map *map;
702 static void free_split(__isl_take struct isl_aff_split *split, int n)
704 int i;
706 if (!split)
707 return;
709 for (i = 0; i < n; ++i) {
710 isl_basic_map_free(split[i].aff);
711 isl_map_free(split[i].map);
714 free(split);
717 static __isl_give isl_basic_map *get_aff(__isl_take isl_basic_map *bmap)
719 int i, j;
720 unsigned nparam, n_in, n_out, total;
722 bmap = isl_basic_map_cow(bmap);
723 if (!bmap)
724 return NULL;
725 if (isl_basic_map_free_inequality(bmap, bmap->n_ineq) < 0)
726 goto error;
728 nparam = isl_basic_map_dim(bmap, isl_dim_param);
729 n_in = isl_basic_map_dim(bmap, isl_dim_in);
730 n_out = isl_basic_map_dim(bmap, isl_dim_out);
731 total = isl_basic_map_dim(bmap, isl_dim_all);
732 for (i = bmap->n_eq - 1; i >= 0; --i) {
733 j = isl_seq_last_non_zero(bmap->eq[i] + 1, total);
734 if (j >= nparam && j < nparam + n_in + n_out &&
735 (isl_int_is_one(bmap->eq[i][1 + j]) ||
736 isl_int_is_negone(bmap->eq[i][1 + j])))
737 continue;
738 if (isl_basic_map_drop_equality(bmap, i) < 0)
739 goto error;
742 bmap = isl_basic_map_finalize(bmap);
744 return bmap;
745 error:
746 isl_basic_map_free(bmap);
747 return NULL;
750 static int aff_split_cmp(const void *p1, const void *p2)
752 const struct isl_aff_split *s1, *s2;
753 s1 = (const struct isl_aff_split *) p1;
754 s2 = (const struct isl_aff_split *) p2;
756 return isl_basic_map_fast_cmp(s1->aff, s2->aff);
759 static __isl_give isl_basic_map *drop_aff(__isl_take isl_basic_map *bmap,
760 __isl_keep isl_basic_map *aff)
762 int i, j;
763 unsigned total;
765 if (!bmap || !aff)
766 goto error;
768 total = isl_dim_total(bmap->dim);
770 for (i = bmap->n_eq - 1; i >= 0; --i) {
771 if (isl_seq_first_non_zero(bmap->eq[i] + 1 + total,
772 bmap->n_div) != -1)
773 continue;
774 for (j = 0; j < aff->n_eq; ++j) {
775 if (!isl_seq_eq(bmap->eq[i], aff->eq[j], 1 + total) &&
776 !isl_seq_is_neg(bmap->eq[i], aff->eq[j], 1 + total))
777 continue;
778 if (isl_basic_map_drop_equality(bmap, i) < 0)
779 goto error;
780 break;
784 return bmap;
785 error:
786 isl_basic_map_free(bmap);
787 return NULL;
790 static __isl_give struct isl_aff_split *split_aff(__isl_keep isl_map *map)
792 int i, n;
793 struct isl_aff_split *split;
795 split = isl_calloc_array(map->isl, struct isl_aff_split, map->n);
796 if (!split)
797 return NULL;
799 for (i = 0; i < map->n; ++i) {
800 isl_basic_map *bmap;
801 split[i].aff = get_aff(isl_basic_map_copy(map->p[i]));
802 bmap = isl_basic_map_copy(map->p[i]);
803 bmap = isl_basic_map_cow(bmap);
804 bmap = drop_aff(bmap, split[i].aff);
805 split[i].map = isl_map_from_basic_map(bmap);
806 if (!split[i].aff || !split[i].map)
807 goto error;
810 qsort(split, map->n, sizeof(struct isl_aff_split), &aff_split_cmp);
812 n = map->n;
813 for (i = n - 1; i >= 1; --i) {
814 if (!isl_basic_map_fast_is_equal(split[i - 1].aff,
815 split[i].aff))
816 continue;
817 isl_basic_map_free(split[i].aff);
818 split[i - 1].map = isl_map_union(split[i - 1].map,
819 split[i].map);
820 if (i != n - 1)
821 split[i] = split[n - 1];
822 split[n - 1].aff = NULL;
823 split[n - 1].map = NULL;
824 --n;
827 return split;
828 error:
829 free_split(split, map->n);
830 return NULL;
833 static __isl_give isl_printer *print_split_map(__isl_take isl_printer *p,
834 struct isl_aff_split *split, int n, int set)
836 int i;
838 for (i = 0; i < n; ++i) {
839 isl_dim *dim;
841 if (!split[i].map)
842 break;
843 dim = split[i].map->dim;
844 if (i)
845 p = isl_printer_print_str(p, "; ");
846 p = print_dim(dim, p, set, 0, split[i].aff);
847 p = print_disjuncts(split[i].map, p, set, 0);
850 return p;
853 static __isl_give isl_printer *isl_map_print_isl_body(__isl_keep isl_map *map,
854 __isl_take isl_printer *p, int set)
856 struct isl_aff_split *split = NULL;
858 if (map->n > 0)
859 split = split_aff(map);
860 if (split) {
861 p = print_split_map(p, split, map->n, set);
862 } else {
863 p = print_dim(map->dim, p, set, 0, NULL);
864 p = print_disjuncts(map, p, set, 0);
866 free_split(split, map->n);
867 return p;
870 static __isl_give isl_printer *isl_map_print_isl(__isl_keep isl_map *map,
871 __isl_take isl_printer *p, int set)
873 if (isl_map_dim(map, isl_dim_param) > 0) {
874 p = print_tuple(map->dim, p, isl_dim_param, set, 0, NULL);
875 p = isl_printer_print_str(p, s_to[0]);
877 p = isl_printer_print_str(p, s_open_set[0]);
878 p = isl_map_print_isl_body(map, p, set);
879 p = isl_printer_print_str(p, s_close_set[0]);
880 return p;
883 static __isl_give isl_printer *print_latex_map(__isl_keep isl_map *map,
884 __isl_take isl_printer *p, __isl_keep isl_basic_map *aff, int set)
886 if (isl_map_dim(map, isl_dim_param) > 0) {
887 p = print_tuple(map->dim, p, isl_dim_param, set, 1, NULL);
888 p = isl_printer_print_str(p, s_to[1]);
890 p = isl_printer_print_str(p, s_open_set[1]);
891 p = print_dim(map->dim, p, set, 1, aff);
892 p = print_disjuncts(map, p, set, 1);
893 p = isl_printer_print_str(p, s_close_set[1]);
895 return p;
898 static __isl_give isl_printer *isl_map_print_latex(__isl_keep isl_map *map,
899 __isl_take isl_printer *p, int set)
901 int i;
902 struct isl_aff_split *split = NULL;
904 if (map->n > 0)
905 split = split_aff(map);
907 if (!split)
908 return print_latex_map(map, p, NULL, set);
910 for (i = 0; i < map->n; ++i) {
911 if (!split[i].map)
912 break;
913 if (i)
914 p = isl_printer_print_str(p, " \\cup ");
915 p = print_latex_map(split[i].map, p, split[i].aff, set);
918 free_split(split, map->n);
919 return p;
922 __isl_give isl_printer *isl_printer_print_basic_map(__isl_take isl_printer *p,
923 __isl_keep isl_basic_map *bmap)
925 if (!p || !bmap)
926 goto error;
927 if (p->output_format == ISL_FORMAT_ISL)
928 return isl_basic_map_print_isl(bmap, p, 0);
929 else if (p->output_format == ISL_FORMAT_OMEGA)
930 return isl_basic_map_print_omega(bmap, p);
931 isl_assert(bmap->ctx, 0, goto error);
932 error:
933 isl_printer_free(p);
934 return NULL;
937 void isl_basic_map_print(__isl_keep isl_basic_map *bmap, FILE *out, int indent,
938 const char *prefix, const char *suffix, unsigned output_format)
940 isl_printer *printer;
942 if (!bmap)
943 return;
945 printer = isl_printer_to_file(bmap->ctx, out);
946 printer = isl_printer_set_indent(printer, indent);
947 printer = isl_printer_set_prefix(printer, prefix);
948 printer = isl_printer_set_suffix(printer, suffix);
949 printer = isl_printer_set_output_format(printer, output_format);
950 isl_printer_print_basic_map(printer, bmap);
952 isl_printer_free(printer);
955 __isl_give isl_printer *isl_printer_print_basic_set(__isl_take isl_printer *p,
956 __isl_keep isl_basic_set *bset)
958 if (!p || !bset)
959 goto error;
961 if (p->output_format == ISL_FORMAT_ISL)
962 return isl_basic_set_print_isl(bset, p, 0);
963 else if (p->output_format == ISL_FORMAT_POLYLIB)
964 return isl_basic_set_print_polylib(bset, p, 0);
965 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
966 return isl_basic_set_print_polylib(bset, p, 1);
967 else if (p->output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
968 return bset_print_constraints_polylib(bset, p);
969 else if (p->output_format == ISL_FORMAT_OMEGA)
970 return isl_basic_set_print_omega(bset, p);
971 isl_assert(p->ctx, 0, goto error);
972 error:
973 isl_printer_free(p);
974 return NULL;
977 void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
978 const char *prefix, const char *suffix, unsigned output_format)
980 isl_printer *printer;
982 if (!bset)
983 return;
985 printer = isl_printer_to_file(bset->ctx, out);
986 printer = isl_printer_set_indent(printer, indent);
987 printer = isl_printer_set_prefix(printer, prefix);
988 printer = isl_printer_set_suffix(printer, suffix);
989 printer = isl_printer_set_output_format(printer, output_format);
990 isl_printer_print_basic_set(printer, bset);
992 isl_printer_free(printer);
995 __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *p,
996 __isl_keep isl_set *set)
998 if (!p || !set)
999 goto error;
1000 if (p->output_format == ISL_FORMAT_ISL)
1001 return isl_map_print_isl((isl_map *)set, p, 1);
1002 else if (p->output_format == ISL_FORMAT_POLYLIB)
1003 return isl_set_print_polylib(set, p, 0);
1004 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1005 return isl_set_print_polylib(set, p, 1);
1006 else if (p->output_format == ISL_FORMAT_OMEGA)
1007 return isl_set_print_omega(set, p);
1008 else if (p->output_format == ISL_FORMAT_LATEX)
1009 return isl_map_print_latex((isl_map *)set, p, 1);
1010 isl_assert(set->ctx, 0, goto error);
1011 error:
1012 isl_printer_free(p);
1013 return NULL;
1016 void isl_set_print(struct isl_set *set, FILE *out, int indent,
1017 unsigned output_format)
1019 isl_printer *printer;
1021 if (!set)
1022 return;
1024 printer = isl_printer_to_file(set->ctx, out);
1025 printer = isl_printer_set_indent(printer, indent);
1026 printer = isl_printer_set_output_format(printer, output_format);
1027 printer = isl_printer_print_set(printer, set);
1029 isl_printer_free(printer);
1032 __isl_give isl_printer *isl_printer_print_map(__isl_take isl_printer *p,
1033 __isl_keep isl_map *map)
1035 if (!p || !map)
1036 goto error;
1038 if (p->output_format == ISL_FORMAT_ISL)
1039 return isl_map_print_isl(map, p, 0);
1040 else if (p->output_format == ISL_FORMAT_POLYLIB)
1041 return isl_map_print_polylib(map, p, 0);
1042 else if (p->output_format == ISL_FORMAT_EXT_POLYLIB)
1043 return isl_map_print_polylib(map, p, 1);
1044 else if (p->output_format == ISL_FORMAT_OMEGA)
1045 return isl_map_print_omega(map, p);
1046 else if (p->output_format == ISL_FORMAT_LATEX)
1047 return isl_map_print_latex(map, p, 0);
1048 isl_assert(map->ctx, 0, goto error);
1049 error:
1050 isl_printer_free(p);
1051 return NULL;
1054 struct isl_union_print_data {
1055 isl_printer *p;
1056 int set;
1057 int first;
1060 static int print_map_body(__isl_take isl_map *map, void *user)
1062 struct isl_union_print_data *data;
1063 data = (struct isl_union_print_data *)user;
1065 if (!data->first)
1066 data->p = isl_printer_print_str(data->p, "; ");
1067 data->first = 0;
1069 data->p = isl_map_print_isl_body(map, data->p, data->set);
1070 isl_map_free(map);
1072 return 0;
1075 static __isl_give isl_printer *isl_union_map_print_isl(
1076 __isl_keep isl_union_map *umap, __isl_take isl_printer *p, int set)
1078 struct isl_union_print_data data = { p, set, 1 };
1079 isl_dim *dim;
1080 dim = isl_union_map_get_dim(umap);
1081 if (isl_dim_size(dim, isl_dim_param) > 0) {
1082 p = print_tuple(dim, p, isl_dim_param, set, 0, NULL);
1083 p = isl_printer_print_str(p, s_to[0]);
1085 isl_dim_free(dim);
1086 p = isl_printer_print_str(p, s_open_set[0]);
1087 isl_union_map_foreach_map(umap, &print_map_body, &data);
1088 p = data.p;
1089 p = isl_printer_print_str(p, s_close_set[0]);
1090 return p;
1093 static int print_latex_map_body(__isl_take isl_map *map, void *user)
1095 struct isl_union_print_data *data;
1096 data = (struct isl_union_print_data *)user;
1098 if (!data->first)
1099 data->p = isl_printer_print_str(data->p, " \\cup ");
1100 data->first = 0;
1102 data->p = isl_map_print_latex(map, data->p, data->set);
1103 isl_map_free(map);
1105 return 0;
1108 static __isl_give isl_printer *isl_union_map_print_latex(
1109 __isl_keep isl_union_map *umap, __isl_take isl_printer *p, int set)
1111 struct isl_union_print_data data = { p, set, 1 };
1112 isl_union_map_foreach_map(umap, &print_latex_map_body, &data);
1113 p = data.p;
1114 return p;
1117 __isl_give isl_printer *isl_printer_print_union_map(__isl_take isl_printer *p,
1118 __isl_keep isl_union_map *umap)
1120 if (!p || !umap)
1121 goto error;
1123 if (p->output_format == ISL_FORMAT_ISL)
1124 return isl_union_map_print_isl(umap, p, 0);
1125 if (p->output_format == ISL_FORMAT_LATEX)
1126 return isl_union_map_print_latex(umap, p, 0);
1128 isl_die(p->ctx, isl_error_invalid,
1129 "invalid output format for isl_union_map", goto error);
1130 error:
1131 isl_printer_free(p);
1132 return NULL;
1135 __isl_give isl_printer *isl_printer_print_union_set(__isl_take isl_printer *p,
1136 __isl_keep isl_union_set *uset)
1138 if (!p || !uset)
1139 goto error;
1141 if (p->output_format == ISL_FORMAT_ISL)
1142 return isl_union_map_print_isl((isl_union_map *)uset, p, 1);
1143 if (p->output_format == ISL_FORMAT_LATEX)
1144 return isl_union_map_print_latex((isl_union_map *)uset, p, 1);
1146 isl_die(p->ctx, isl_error_invalid,
1147 "invalid output format for isl_union_set", goto error);
1148 error:
1149 isl_printer_free(p);
1150 return NULL;
1153 void isl_map_print(__isl_keep isl_map *map, FILE *out, int indent,
1154 unsigned output_format)
1156 isl_printer *printer;
1158 if (!map)
1159 return;
1161 printer = isl_printer_to_file(map->ctx, out);
1162 printer = isl_printer_set_indent(printer, indent);
1163 printer = isl_printer_set_output_format(printer, output_format);
1164 printer = isl_printer_print_map(printer, map);
1166 isl_printer_free(printer);
1169 void isl_basic_map_dump(__isl_keep isl_basic_map *bmap)
1171 isl_printer *printer;
1173 if (!bmap)
1174 return;
1176 printer = isl_printer_to_file(isl_basic_map_get_ctx(bmap), stderr);
1177 printer = isl_printer_print_basic_map(printer, bmap);
1178 printer = isl_printer_end_line(printer);
1180 isl_printer_free(printer);
1183 void isl_basic_set_dump(__isl_keep isl_basic_set *bset)
1185 isl_printer *printer;
1187 if (!bset)
1188 return;
1190 printer = isl_printer_to_file(isl_basic_set_get_ctx(bset), stderr);
1191 printer = isl_printer_print_basic_set(printer, bset);
1192 printer = isl_printer_end_line(printer);
1194 isl_printer_free(printer);
1197 void isl_map_dump(__isl_keep isl_map *map)
1199 isl_printer *printer;
1201 if (!map)
1202 return;
1204 printer = isl_printer_to_file(isl_map_get_ctx(map), stderr);
1205 printer = isl_printer_print_map(printer, map);
1206 printer = isl_printer_end_line(printer);
1208 isl_printer_free(printer);
1211 void isl_set_dump(__isl_keep isl_set *set)
1213 isl_printer *printer;
1215 if (!set)
1216 return;
1218 printer = isl_printer_to_file(isl_set_get_ctx(set), stderr);
1219 printer = isl_printer_print_set(printer, set);
1220 printer = isl_printer_end_line(printer);
1222 isl_printer_free(printer);
1225 void isl_union_map_dump(__isl_keep isl_union_map *umap)
1227 isl_printer *printer;
1229 if (!umap)
1230 return;
1232 printer = isl_printer_to_file(isl_union_map_get_ctx(umap), stderr);
1233 printer = isl_printer_print_union_map(printer, umap);
1234 printer = isl_printer_end_line(printer);
1236 isl_printer_free(printer);
1239 void isl_union_set_dump(__isl_keep isl_union_set *uset)
1241 isl_printer *printer;
1243 if (!uset)
1244 return;
1246 printer = isl_printer_to_file(isl_union_set_get_ctx(uset), stderr);
1247 printer = isl_printer_print_union_set(printer, uset);
1248 printer = isl_printer_end_line(printer);
1250 isl_printer_free(printer);
1253 void isl_union_pw_qpolynomial_dump(__isl_keep isl_union_pw_qpolynomial *upwqp)
1255 isl_printer *printer;
1257 if (!upwqp)
1258 return;
1260 printer = isl_printer_to_file(isl_union_pw_qpolynomial_get_ctx(upwqp),
1261 stderr);
1262 printer = isl_printer_print_union_pw_qpolynomial(printer, upwqp);
1263 printer = isl_printer_end_line(printer);
1265 isl_printer_free(printer);
1268 void isl_qpolynomial_dump(__isl_keep isl_qpolynomial *qp)
1270 isl_printer *printer;
1272 if (!qp)
1273 return;
1275 printer = isl_printer_to_file(isl_qpolynomial_get_ctx(qp), stderr);
1276 printer = isl_printer_print_qpolynomial(printer, qp);
1277 printer = isl_printer_end_line(printer);
1279 isl_printer_free(printer);
1282 void isl_qpolynomial_fold_dump(__isl_keep isl_qpolynomial_fold *fold)
1284 isl_printer *printer;
1286 if (!fold)
1287 return;
1289 printer = isl_printer_to_file(isl_qpolynomial_fold_get_ctx(fold),
1290 stderr);
1291 printer = isl_printer_print_qpolynomial_fold(printer, fold);
1292 printer = isl_printer_end_line(printer);
1294 isl_printer_free(printer);
1297 void isl_pw_qpolynomial_dump(__isl_keep isl_pw_qpolynomial *pwqp)
1299 isl_printer *printer;
1301 if (!pwqp)
1302 return;
1304 printer = isl_printer_to_file(isl_pw_qpolynomial_get_ctx(pwqp), stderr);
1305 printer = isl_printer_print_pw_qpolynomial(printer, pwqp);
1306 printer = isl_printer_end_line(printer);
1308 isl_printer_free(printer);
1311 void isl_pw_qpolynomial_fold_dump(__isl_keep isl_pw_qpolynomial_fold *pwf)
1313 isl_printer *printer;
1315 if (!pwf)
1316 return;
1318 printer = isl_printer_to_file(
1319 isl_pw_qpolynomial_fold_get_ctx(pwf), stderr);
1320 printer = isl_printer_print_pw_qpolynomial_fold(printer, pwf);
1321 printer = isl_printer_end_line(printer);
1323 isl_printer_free(printer);
1326 void isl_union_pw_qpolynomial_fold_dump(
1327 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
1329 isl_printer *printer;
1331 if (!upwf)
1332 return;
1334 printer = isl_printer_to_file(
1335 isl_union_pw_qpolynomial_fold_get_ctx(upwf), stderr);
1336 printer = isl_printer_print_union_pw_qpolynomial_fold(printer, upwf);
1337 printer = isl_printer_end_line(printer);
1339 isl_printer_free(printer);
1342 static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
1344 int i;
1345 int n;
1347 for (i = 0, n = 0; i < rec->n; ++i)
1348 if (!isl_upoly_is_zero(rec->p[i]))
1349 ++n;
1351 return n;
1354 static __isl_give isl_printer *print_div(__isl_keep isl_dim *dim,
1355 __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p)
1357 int c = p->output_format == ISL_FORMAT_C;
1358 p = isl_printer_print_str(p, c ? "floord(" : "[(");
1359 p = print_affine_of_len(dim, div, p,
1360 div->row[pos] + 1, div->n_col - 1, 1);
1361 p = isl_printer_print_str(p, c ? ", " : ")/");
1362 p = isl_printer_print_isl_int(p, div->row[pos][0]);
1363 p = isl_printer_print_str(p, c ? ")" : "]");
1364 return p;
1367 static __isl_give isl_printer *upoly_print_cst(__isl_keep struct isl_upoly *up,
1368 __isl_take isl_printer *p, int first)
1370 struct isl_upoly_cst *cst;
1371 int neg;
1373 cst = isl_upoly_as_cst(up);
1374 if (!cst)
1375 goto error;
1376 neg = !first && isl_int_is_neg(cst->n);
1377 if (!first)
1378 p = isl_printer_print_str(p, neg ? " - " : " + ");
1379 if (neg)
1380 isl_int_neg(cst->n, cst->n);
1381 if (isl_int_is_zero(cst->d)) {
1382 int sgn = isl_int_sgn(cst->n);
1383 p = isl_printer_print_str(p, sgn < 0 ? "-infty" :
1384 sgn == 0 ? "NaN" : "infty");
1385 } else
1386 p = isl_printer_print_isl_int(p, cst->n);
1387 if (neg)
1388 isl_int_neg(cst->n, cst->n);
1389 if (!isl_int_is_zero(cst->d) && !isl_int_is_one(cst->d)) {
1390 p = isl_printer_print_str(p, "/");
1391 p = isl_printer_print_isl_int(p, cst->d);
1393 return p;
1394 error:
1395 isl_printer_free(p);
1396 return NULL;
1399 static __isl_give isl_printer *print_base(__isl_take isl_printer *p,
1400 __isl_keep isl_dim *dim, __isl_keep isl_mat *div, int var)
1402 unsigned total;
1404 total = isl_dim_total(dim);
1405 if (var < total)
1406 p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 1, 0);
1407 else
1408 p = print_div(dim, div, var - total, p);
1409 return p;
1412 static __isl_give isl_printer *print_pow(__isl_take isl_printer *p,
1413 __isl_keep isl_dim *dim, __isl_keep isl_mat *div, int var, int exp)
1415 p = print_base(p, dim, div, var);
1416 if (exp == 1)
1417 return p;
1418 if (p->output_format == ISL_FORMAT_C) {
1419 int i;
1420 for (i = 1; i < exp; ++i) {
1421 p = isl_printer_print_str(p, "*");
1422 p = print_base(p, dim, div, var);
1424 } else {
1425 p = isl_printer_print_str(p, "^");
1426 p = isl_printer_print_int(p, exp);
1428 return p;
1431 static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
1432 __isl_keep isl_dim *dim, __isl_keep isl_mat *div,
1433 __isl_take isl_printer *p, int outer)
1435 int i, n, first, print_parens;
1436 struct isl_upoly_rec *rec;
1438 if (!p || !up || !dim || !div)
1439 goto error;
1441 if (isl_upoly_is_cst(up))
1442 return upoly_print_cst(up, p, 1);
1444 rec = isl_upoly_as_rec(up);
1445 if (!rec)
1446 goto error;
1447 n = upoly_rec_n_non_zero(rec);
1448 print_parens = n > 1 || (outer && rec->up.var >= isl_dim_total(dim));
1449 if (print_parens)
1450 p = isl_printer_print_str(p, "(");
1451 for (i = 0, first = 1; i < rec->n; ++i) {
1452 if (isl_upoly_is_zero(rec->p[i]))
1453 continue;
1454 if (isl_upoly_is_negone(rec->p[i])) {
1455 if (!i)
1456 p = isl_printer_print_str(p, "-1");
1457 else if (first)
1458 p = isl_printer_print_str(p, "-");
1459 else
1460 p = isl_printer_print_str(p, " - ");
1461 } else if (isl_upoly_is_cst(rec->p[i]) &&
1462 !isl_upoly_is_one(rec->p[i]))
1463 p = upoly_print_cst(rec->p[i], p, first);
1464 else {
1465 if (!first)
1466 p = isl_printer_print_str(p, " + ");
1467 if (i == 0 || !isl_upoly_is_one(rec->p[i]))
1468 p = upoly_print(rec->p[i], dim, div, p, 0);
1470 first = 0;
1471 if (i == 0)
1472 continue;
1473 if (!isl_upoly_is_one(rec->p[i]) &&
1474 !isl_upoly_is_negone(rec->p[i]))
1475 p = isl_printer_print_str(p, " * ");
1476 p = print_pow(p, dim, div, rec->up.var, i);
1478 if (print_parens)
1479 p = isl_printer_print_str(p, ")");
1480 return p;
1481 error:
1482 isl_printer_free(p);
1483 return NULL;
1486 __isl_give isl_printer *isl_printer_print_qpolynomial(__isl_take isl_printer *p,
1487 __isl_keep isl_qpolynomial *qp)
1489 if (!p || !qp)
1490 goto error;
1491 p = upoly_print(qp->upoly, qp->dim, qp->div, p, 1);
1492 return p;
1493 error:
1494 isl_printer_free(p);
1495 return NULL;
1498 void isl_qpolynomial_print(__isl_keep isl_qpolynomial *qp, FILE *out,
1499 unsigned output_format)
1501 isl_printer *p;
1503 if (!qp)
1504 return;
1506 isl_assert(qp->dim->ctx, output_format == ISL_FORMAT_ISL, return);
1507 p = isl_printer_to_file(qp->dim->ctx, out);
1508 p = isl_printer_print_qpolynomial(p, qp);
1509 isl_printer_free(p);
1512 static __isl_give isl_printer *qpolynomial_fold_print(
1513 __isl_keep isl_qpolynomial_fold *fold, __isl_take isl_printer *p)
1515 int i;
1517 if (fold->type == isl_fold_min)
1518 p = isl_printer_print_str(p, "min");
1519 else if (fold->type == isl_fold_max)
1520 p = isl_printer_print_str(p, "max");
1521 p = isl_printer_print_str(p, "(");
1522 for (i = 0; i < fold->n; ++i) {
1523 if (i)
1524 p = isl_printer_print_str(p, ", ");
1525 p = isl_printer_print_qpolynomial(p, fold->qp[i]);
1527 p = isl_printer_print_str(p, ")");
1528 return p;
1531 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold *fold,
1532 FILE *out, unsigned output_format)
1534 isl_printer *p;
1536 if (!fold)
1537 return;
1539 isl_assert(fold->dim->ctx, output_format == ISL_FORMAT_ISL, return);
1541 p = isl_printer_to_file(fold->dim->ctx, out);
1542 p = isl_printer_print_qpolynomial_fold(p, fold);
1544 isl_printer_free(p);
1547 static __isl_give isl_printer *isl_pwqp_print_isl_body(
1548 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1550 int i = 0;
1552 for (i = 0; i < pwqp->n; ++i) {
1553 if (i)
1554 p = isl_printer_print_str(p, "; ");
1555 if (isl_dim_size(pwqp->dim, isl_dim_set) > 0 ||
1556 isl_dim_is_named_or_nested(pwqp->dim, isl_dim_set)) {
1557 p = print_dim(pwqp->p[i].set->dim, p, 1, 0, NULL);
1558 p = isl_printer_print_str(p, " -> ");
1560 p = isl_printer_print_qpolynomial(p, pwqp->p[i].qp);
1561 p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 1, 0);
1564 return p;
1567 static __isl_give isl_printer *print_pw_qpolynomial_isl(
1568 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1570 if (!p || !pwqp)
1571 goto error;
1573 if (isl_dim_size(pwqp->dim, isl_dim_param) > 0) {
1574 p = print_tuple(pwqp->dim, p, isl_dim_param, 0, 0, NULL);
1575 p = isl_printer_print_str(p, " -> ");
1577 p = isl_printer_print_str(p, "{ ");
1578 if (pwqp->n == 0) {
1579 if (isl_dim_size(pwqp->dim, isl_dim_set) > 0 ||
1580 isl_dim_is_named_or_nested(pwqp->dim, isl_dim_set)) {
1581 p = print_dim(pwqp->dim, p, 1, 0, NULL);
1582 p = isl_printer_print_str(p, " -> ");
1584 p = isl_printer_print_str(p, "0");
1586 p = isl_pwqp_print_isl_body(p, pwqp);
1587 p = isl_printer_print_str(p, " }");
1588 return p;
1589 error:
1590 isl_printer_free(p);
1591 return NULL;
1594 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial *pwqp, FILE *out,
1595 unsigned output_format)
1597 isl_printer *p;
1599 if (!pwqp)
1600 return;
1602 p = isl_printer_to_file(pwqp->dim->ctx, out);
1603 p = isl_printer_set_output_format(p, output_format);
1604 p = isl_printer_print_pw_qpolynomial(p, pwqp);
1606 isl_printer_free(p);
1609 static __isl_give isl_printer *isl_pwf_print_isl_body(
1610 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1612 int i = 0;
1614 for (i = 0; i < pwf->n; ++i) {
1615 if (i)
1616 p = isl_printer_print_str(p, "; ");
1617 if (isl_dim_size(pwf->dim, isl_dim_set) > 0 ||
1618 isl_dim_is_named_or_nested(pwf->dim, isl_dim_set)) {
1619 p = print_dim(pwf->p[i].set->dim, p, 1, 0, NULL);
1620 p = isl_printer_print_str(p, " -> ");
1622 p = qpolynomial_fold_print(pwf->p[i].fold, p);
1623 p = print_disjuncts((isl_map *)pwf->p[i].set, p, 1, 0);
1626 return p;
1629 static __isl_give isl_printer *print_pw_qpolynomial_fold_isl(
1630 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1632 if (isl_dim_size(pwf->dim, isl_dim_param) > 0) {
1633 p = print_tuple(pwf->dim, p, isl_dim_param, 0, 0, NULL);
1634 p = isl_printer_print_str(p, " -> ");
1636 p = isl_printer_print_str(p, "{ ");
1637 if (pwf->n == 0) {
1638 if (isl_dim_size(pwf->dim, isl_dim_set) > 0 ||
1639 isl_dim_is_named_or_nested(pwf->dim, isl_dim_set)) {
1640 p = print_dim(pwf->dim, p, 1, 0, NULL);
1641 p = isl_printer_print_str(p, " -> ");
1643 p = isl_printer_print_str(p, "0");
1645 p = isl_pwf_print_isl_body(p, pwf);
1646 p = isl_printer_print_str(p, " }");
1647 return p;
1650 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1651 __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset, isl_int *c);
1653 static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
1654 __isl_keep isl_dim *dim,
1655 __isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
1657 if (type == isl_dim_div) {
1658 p = isl_printer_print_str(p, "floord(");
1659 p = print_affine_c(p, dim, bset, bset->div[pos] + 1);
1660 p = isl_printer_print_str(p, ", ");
1661 p = isl_printer_print_isl_int(p, bset->div[pos][0]);
1662 p = isl_printer_print_str(p, ")");
1663 } else {
1664 const char *name;
1666 name = isl_dim_get_name(dim, type, pos);
1667 if (!name)
1668 name = "UNNAMED";
1669 p = isl_printer_print_str(p, name);
1671 return p;
1674 static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
1675 __isl_keep isl_dim *dim,
1676 __isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
1678 enum isl_dim_type type;
1679 unsigned nparam = isl_basic_set_dim(bset, isl_dim_param);
1681 if (pos == 0)
1682 return isl_printer_print_isl_int(p, c);
1684 if (isl_int_is_one(c))
1686 else if (isl_int_is_negone(c))
1687 p = isl_printer_print_str(p, "-");
1688 else {
1689 p = isl_printer_print_isl_int(p, c);
1690 p = isl_printer_print_str(p, "*");
1692 type = pos2type(dim, &pos);
1693 p = print_name_c(p, dim, bset, type, pos);
1694 return p;
1697 static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p,
1698 __isl_keep isl_dim *dim,
1699 __isl_keep isl_basic_set *bset, isl_int *c, unsigned len)
1701 int i;
1702 int first;
1704 for (i = 0, first = 1; i < len; ++i) {
1705 int flip = 0;
1706 if (isl_int_is_zero(c[i]))
1707 continue;
1708 if (!first) {
1709 if (isl_int_is_neg(c[i])) {
1710 flip = 1;
1711 isl_int_neg(c[i], c[i]);
1712 p = isl_printer_print_str(p, " - ");
1713 } else
1714 p = isl_printer_print_str(p, " + ");
1716 first = 0;
1717 p = print_term_c(p, dim, bset, c[i], i);
1718 if (flip)
1719 isl_int_neg(c[i], c[i]);
1721 if (first)
1722 p = isl_printer_print_str(p, "0");
1723 return p;
1726 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1727 __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset, isl_int *c)
1729 unsigned len = 1 + isl_basic_set_total_dim(bset);
1730 return print_partial_affine_c(p, dim, bset, c, len);
1733 static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
1734 __isl_keep isl_dim *dim,
1735 __isl_keep isl_basic_set *bset, isl_int *c, const char *op, int first)
1737 if (!first)
1738 p = isl_printer_print_str(p, " && ");
1740 p = print_affine_c(p, dim, bset, c);
1741 p = isl_printer_print_str(p, " ");
1742 p = isl_printer_print_str(p, op);
1743 p = isl_printer_print_str(p, " 0");
1744 return p;
1747 static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
1748 __isl_keep isl_dim *dim, __isl_keep isl_basic_set *bset)
1750 int i, j;
1751 unsigned n_div = isl_basic_set_dim(bset, isl_dim_div);
1752 unsigned total = isl_basic_set_total_dim(bset) - n_div;
1754 for (i = 0; i < bset->n_eq; ++i) {
1755 j = isl_seq_last_non_zero(bset->eq[i] + 1 + total, n_div);
1756 if (j < 0)
1757 p = print_constraint_c(p, dim, bset,
1758 bset->eq[i], "==", !i);
1759 else {
1760 if (i)
1761 p = isl_printer_print_str(p, " && ");
1762 p = isl_printer_print_str(p, "(");
1763 p = print_partial_affine_c(p, dim, bset, bset->eq[i],
1764 1 + total + j);
1765 p = isl_printer_print_str(p, ") % ");
1766 p = isl_printer_print_isl_int(p,
1767 bset->eq[i][1 + total + j]);
1768 p = isl_printer_print_str(p, " == 0");
1771 for (i = 0; i < bset->n_ineq; ++i)
1772 p = print_constraint_c(p, dim, bset, bset->ineq[i], ">=",
1773 !bset->n_eq && !i);
1774 return p;
1777 static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p,
1778 __isl_keep isl_dim *dim, __isl_keep isl_set *set)
1780 int i;
1782 if (set->n == 0)
1783 p = isl_printer_print_str(p, "0");
1785 for (i = 0; i < set->n; ++i) {
1786 if (i)
1787 p = isl_printer_print_str(p, " || ");
1788 if (set->n > 1)
1789 p = isl_printer_print_str(p, "(");
1790 p = print_basic_set_c(p, dim, set->p[i]);
1791 if (set->n > 1)
1792 p = isl_printer_print_str(p, ")");
1794 return p;
1797 static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
1798 __isl_keep isl_dim *dim, __isl_keep isl_qpolynomial *qp)
1800 isl_int den;
1802 isl_int_init(den);
1803 isl_qpolynomial_get_den(qp, &den);
1804 if (!isl_int_is_one(den)) {
1805 isl_qpolynomial *f;
1806 p = isl_printer_print_str(p, "(");
1807 qp = isl_qpolynomial_copy(qp);
1808 f = isl_qpolynomial_rat_cst(isl_dim_copy(qp->dim),
1809 den, qp->dim->ctx->one);
1810 qp = isl_qpolynomial_mul(qp, f);
1812 if (qp)
1813 p = upoly_print(qp->upoly, dim, qp->div, p, 0);
1814 if (!isl_int_is_one(den)) {
1815 p = isl_printer_print_str(p, ")/");
1816 p = isl_printer_print_isl_int(p, den);
1817 isl_qpolynomial_free(qp);
1819 isl_int_clear(den);
1820 return p;
1823 static __isl_give isl_printer *print_pw_qpolynomial_c(
1824 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1826 int i;
1828 if (pwqp->n == 1 && isl_set_fast_is_universe(pwqp->p[0].set))
1829 return print_qpolynomial_c(p, pwqp->dim, pwqp->p[0].qp);
1831 for (i = 0; i < pwqp->n; ++i) {
1832 p = isl_printer_print_str(p, "(");
1833 p = print_set_c(p, pwqp->dim, pwqp->p[i].set);
1834 p = isl_printer_print_str(p, ") ? (");
1835 p = print_qpolynomial_c(p, pwqp->dim, pwqp->p[i].qp);
1836 p = isl_printer_print_str(p, ") : ");
1839 p = isl_printer_print_str(p, "0");
1840 return p;
1843 __isl_give isl_printer *isl_printer_print_pw_qpolynomial(
1844 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1846 if (!p || !pwqp)
1847 goto error;
1849 if (p->output_format == ISL_FORMAT_ISL)
1850 return print_pw_qpolynomial_isl(p, pwqp);
1851 else if (p->output_format == ISL_FORMAT_C)
1852 return print_pw_qpolynomial_c(p, pwqp);
1853 isl_assert(p->ctx, 0, goto error);
1854 error:
1855 isl_printer_free(p);
1856 return NULL;
1859 static int print_pwqp_body(__isl_take isl_pw_qpolynomial *pwqp, void *user)
1861 struct isl_union_print_data *data;
1862 data = (struct isl_union_print_data *)user;
1864 if (!data->first)
1865 data->p = isl_printer_print_str(data->p, "; ");
1866 data->first = 0;
1868 data->p = isl_pwqp_print_isl_body(data->p, pwqp);
1869 isl_pw_qpolynomial_free(pwqp);
1871 return 0;
1874 static __isl_give isl_printer *print_union_pw_qpolynomial_isl(
1875 __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
1877 struct isl_union_print_data data = { p, 1, 1 };
1878 isl_dim *dim;
1879 dim = isl_union_pw_qpolynomial_get_dim(upwqp);
1880 if (isl_dim_size(dim, isl_dim_param) > 0) {
1881 p = print_tuple(dim, p, isl_dim_param, 1, 0, NULL);
1882 p = isl_printer_print_str(p, " -> ");
1884 isl_dim_free(dim);
1885 p = isl_printer_print_str(p, "{ ");
1886 isl_union_pw_qpolynomial_foreach_pw_qpolynomial(upwqp, &print_pwqp_body,
1887 &data);
1888 p = data.p;
1889 p = isl_printer_print_str(p, " }");
1890 return p;
1893 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial(
1894 __isl_take isl_printer *p, __isl_keep isl_union_pw_qpolynomial *upwqp)
1896 if (!p || !upwqp)
1897 goto error;
1899 if (p->output_format == ISL_FORMAT_ISL)
1900 return print_union_pw_qpolynomial_isl(p, upwqp);
1901 isl_die(p->ctx, isl_error_invalid,
1902 "invalid output format for isl_union_pw_qpolynomial",
1903 goto error);
1904 error:
1905 isl_printer_free(p);
1906 return NULL;
1909 static __isl_give isl_printer *print_qpolynomial_fold_c(
1910 __isl_take isl_printer *p, __isl_keep isl_dim *dim,
1911 __isl_keep isl_qpolynomial_fold *fold)
1913 int i;
1915 for (i = 0; i < fold->n - 1; ++i)
1916 if (fold->type == isl_fold_min)
1917 p = isl_printer_print_str(p, "min(");
1918 else if (fold->type == isl_fold_max)
1919 p = isl_printer_print_str(p, "max(");
1921 for (i = 0; i < fold->n; ++i) {
1922 if (i)
1923 p = isl_printer_print_str(p, ", ");
1924 p = print_qpolynomial_c(p, dim, fold->qp[i]);
1925 if (i)
1926 p = isl_printer_print_str(p, ")");
1928 return p;
1931 __isl_give isl_printer *isl_printer_print_qpolynomial_fold(
1932 __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
1934 if (!p || !fold)
1935 goto error;
1936 if (p->output_format == ISL_FORMAT_ISL)
1937 return qpolynomial_fold_print(fold, p);
1938 else if (p->output_format == ISL_FORMAT_C)
1939 return print_qpolynomial_fold_c(p, fold->dim, fold);
1940 isl_die(p->ctx, isl_error_unsupported, "unsupported output format",
1941 goto error);
1942 error:
1943 isl_printer_free(p);
1944 return NULL;
1947 static __isl_give isl_printer *print_pw_qpolynomial_fold_c(
1948 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1950 int i;
1952 if (pwf->n == 1 && isl_set_fast_is_universe(pwf->p[0].set))
1953 return print_qpolynomial_fold_c(p, pwf->dim, pwf->p[0].fold);
1955 for (i = 0; i < pwf->n; ++i) {
1956 p = isl_printer_print_str(p, "(");
1957 p = print_set_c(p, pwf->dim, pwf->p[i].set);
1958 p = isl_printer_print_str(p, ") ? (");
1959 p = print_qpolynomial_fold_c(p, pwf->dim, pwf->p[i].fold);
1960 p = isl_printer_print_str(p, ") : ");
1963 p = isl_printer_print_str(p, "0");
1964 return p;
1967 __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
1968 __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1970 if (!p || !pwf)
1971 goto error;
1973 if (p->output_format == ISL_FORMAT_ISL)
1974 return print_pw_qpolynomial_fold_isl(p, pwf);
1975 else if (p->output_format == ISL_FORMAT_C)
1976 return print_pw_qpolynomial_fold_c(p, pwf);
1977 isl_assert(p->ctx, 0, goto error);
1978 error:
1979 isl_printer_free(p);
1980 return NULL;
1983 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold *pwf,
1984 FILE *out, unsigned output_format)
1986 isl_printer *p;
1988 if (!pwf)
1989 return;
1991 p = isl_printer_to_file(pwf->dim->ctx, out);
1992 p = isl_printer_set_output_format(p, output_format);
1993 p = isl_printer_print_pw_qpolynomial_fold(p, pwf);
1995 isl_printer_free(p);
1998 static int print_pwf_body(__isl_take isl_pw_qpolynomial_fold *pwf, void *user)
2000 struct isl_union_print_data *data;
2001 data = (struct isl_union_print_data *)user;
2003 if (!data->first)
2004 data->p = isl_printer_print_str(data->p, "; ");
2005 data->first = 0;
2007 data->p = isl_pwf_print_isl_body(data->p, pwf);
2008 isl_pw_qpolynomial_fold_free(pwf);
2010 return 0;
2013 static __isl_give isl_printer *print_union_pw_qpolynomial_fold_isl(
2014 __isl_take isl_printer *p,
2015 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
2017 struct isl_union_print_data data = { p, 1, 1 };
2018 isl_dim *dim;
2019 dim = isl_union_pw_qpolynomial_fold_get_dim(upwf);
2020 if (isl_dim_size(dim, isl_dim_param) > 0) {
2021 p = print_tuple(dim, p, isl_dim_param, 1, 0, NULL);
2022 p = isl_printer_print_str(p, " -> ");
2024 isl_dim_free(dim);
2025 p = isl_printer_print_str(p, "{ ");
2026 isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold(upwf,
2027 &print_pwf_body, &data);
2028 p = data.p;
2029 p = isl_printer_print_str(p, " }");
2030 return p;
2033 __isl_give isl_printer *isl_printer_print_union_pw_qpolynomial_fold(
2034 __isl_take isl_printer *p,
2035 __isl_keep isl_union_pw_qpolynomial_fold *upwf)
2037 if (!p || !upwf)
2038 goto error;
2040 if (p->output_format == ISL_FORMAT_ISL)
2041 return print_union_pw_qpolynomial_fold_isl(p, upwf);
2042 isl_die(p->ctx, isl_error_invalid,
2043 "invalid output format for isl_union_pw_qpolynomial_fold",
2044 goto error);
2045 error:
2046 isl_printer_free(p);
2047 return NULL;