isl_map_transitive_closure: handle existentials
[platform/upstream/isl.git] / isl_output.c
1 /*
2  * Copyright 2008-2009 Katholieke Universiteit Leuven
3  * Copyright 2010      INRIA Saclay
4  *
5  * Use of this software is governed by the GNU LGPLv2.1 license
6  *
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 
11  */
12
13 #include <string.h>
14 #include <isl_set.h>
15 #include <isl_seq.h>
16 #include <isl_polynomial_private.h>
17 #include <isl_printer_private.h>
18
19 static const char *s_to[2] = { " -> ", " \\to " };
20 static const char *s_and[2] = { " and ", " \\wedge " };
21 static const char *s_or[2] = { " or ", " \\vee " };
22 static const char *s_le[2] = { "<=", "\\le" };
23 static const char *s_ge[2] = { ">=", "\\ge" };
24 static const char *s_open_set[2] = { "{ ", "\\{\\, " };
25 static const char *s_close_set[2] = { " }", " \\,\\}" };
26 static const char *s_open_list[2] = { "[", "(" };
27 static const char *s_close_list[2] = { "]", ")" };
28 static const char *s_such_that[2] = { " : ", " \\mid " };
29 static const char *s_open_exists[2] = { "exists (", "\\exists \\, " };
30 static const char *s_close_exists[2] = { ")", "" };
31 static const char *s_div_prefix[2] = { "e", "\\alpha_" };
32 static const char *s_param_prefix[2] = { "p", "p_" };
33 static const char *s_input_prefix[2] = { "i", "i_" };
34 static const char *s_output_prefix[2] = { "o", "o_" };
35
36 static __isl_give isl_printer *print_constraint_polylib(
37         struct isl_basic_map *bmap, int ineq, int n, __isl_take isl_printer *p)
38 {
39         int i;
40         unsigned n_in = isl_basic_map_dim(bmap, isl_dim_in);
41         unsigned n_out = isl_basic_map_dim(bmap, isl_dim_out);
42         unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param);
43         isl_int *c = ineq ? bmap->ineq[n] : bmap->eq[n];
44
45         p = isl_printer_start_line(p);
46         p = isl_printer_print_int(p, ineq);
47         for (i = 0; i < n_out; ++i) {
48                 p = isl_printer_print_str(p, " ");
49                 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+i]);
50         }
51         for (i = 0; i < n_in; ++i) {
52                 p = isl_printer_print_str(p, " ");
53                 p = isl_printer_print_isl_int(p, c[1+nparam+i]);
54         }
55         for (i = 0; i < bmap->n_div; ++i) {
56                 p = isl_printer_print_str(p, " ");
57                 p = isl_printer_print_isl_int(p, c[1+nparam+n_in+n_out+i]);
58         }
59         for (i = 0; i < nparam; ++i) {
60                 p = isl_printer_print_str(p, " ");
61                 p = isl_printer_print_isl_int(p, c[1+i]);
62         }
63         p = isl_printer_print_str(p, " ");
64         p = isl_printer_print_isl_int(p, c[0]);
65         p = isl_printer_end_line(p);
66         return p;
67 }
68
69 static __isl_give isl_printer *print_constraints_polylib(
70         struct isl_basic_map *bmap, __isl_take isl_printer *p)
71 {
72         int i;
73
74         p = isl_printer_set_isl_int_width(p, 5);
75
76         for (i = 0; i < bmap->n_eq; ++i)
77                 p = print_constraint_polylib(bmap, 0, i, p);
78         for (i = 0; i < bmap->n_ineq; ++i)
79                 p = print_constraint_polylib(bmap, 1, i, p);
80
81         return p;
82 }
83
84 static __isl_give isl_printer *bset_print_constraints_polylib(
85         struct isl_basic_set *bset, __isl_take isl_printer *p)
86 {
87         return print_constraints_polylib((struct isl_basic_map *)bset, p);
88 }
89
90 static __isl_give isl_printer *isl_basic_map_print_polylib(
91         __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
92 {
93         unsigned total = isl_basic_map_total_dim(bmap);
94         p = isl_printer_start_line(p);
95         p = isl_printer_print_int(p, bmap->n_eq + bmap->n_ineq);
96         p = isl_printer_print_str(p, " ");
97         p = isl_printer_print_int(p, 1 + total + 1);
98         p = isl_printer_end_line(p);
99         return print_constraints_polylib(bmap, p);
100 }
101
102 static __isl_give isl_printer *isl_basic_set_print_polylib(
103         __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
104 {
105         return isl_basic_map_print_polylib((struct isl_basic_map *)bset, p);
106 }
107
108 static __isl_give isl_printer *isl_map_print_polylib(__isl_keep isl_map *map,
109         __isl_take isl_printer *p)
110 {
111         int i;
112
113         p = isl_printer_start_line(p);
114         p = isl_printer_print_int(p, map->n);
115         p = isl_printer_end_line(p);
116         for (i = 0; i < map->n; ++i) {
117                 p = isl_printer_start_line(p);
118                 p = isl_printer_end_line(p);
119                 p = isl_basic_map_print_polylib(map->p[i], p);
120         }
121         return p;
122 }
123
124 static __isl_give isl_printer *isl_set_print_polylib(__isl_keep isl_set *set,
125         __isl_take isl_printer *p)
126 {
127         return isl_map_print_polylib((struct isl_map *)set, p);
128 }
129
130 static int count_same_name(__isl_keep isl_dim *dim,
131         enum isl_dim_type type, unsigned pos, const char *name)
132 {
133         enum isl_dim_type t;
134         unsigned p, s;
135         int count = 0;
136
137         for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) {
138                 s = t == type ? pos : isl_dim_size(dim, t);
139                 for (p = 0; p < s; ++p) {
140                         const char *n = isl_dim_get_name(dim, t, p);
141                         if (n && !strcmp(n, name))
142                                 count++;
143                 }
144         }
145         return count;
146 }
147
148 static __isl_give isl_printer *print_name(__isl_keep isl_dim *dim,
149         __isl_take isl_printer *p, enum isl_dim_type type, unsigned pos,
150         int set, int latex)
151 {
152         const char *name;
153         char buffer[20];
154         int primes;
155
156         name = type == isl_dim_div ? NULL : isl_dim_get_name(dim, type, pos);
157
158         if (!name) {
159                 const char *prefix;
160                 if (type == isl_dim_param)
161                         prefix = s_param_prefix[latex];
162                 else if (type == isl_dim_div)
163                         prefix = s_div_prefix[latex];
164                 else if (set || type == isl_dim_in)
165                         prefix = s_input_prefix[latex];
166                 else
167                         prefix = s_output_prefix[latex];
168                 snprintf(buffer, sizeof(buffer), "%s%d", prefix, pos);
169                 name = buffer;
170         }
171         primes = count_same_name(dim, name == buffer ? isl_dim_div : type,
172                                  pos, name);
173         p = isl_printer_print_str(p, name);
174         while (primes-- > 0)
175                 p = isl_printer_print_str(p, "'");
176         return p;
177 }
178
179 static __isl_give isl_printer *print_var_list(__isl_keep isl_dim *dim,
180         __isl_take isl_printer *p, enum isl_dim_type type, int set, int latex)
181 {
182         int i;
183
184         for (i = 0; i < isl_dim_size(dim, type); ++i) {
185                 if (i)
186                         p = isl_printer_print_str(p, ", ");
187                 p = print_name(dim, p, type, i, set, latex);
188         }
189         return p;
190 }
191
192 static __isl_give isl_printer *print_tuple(__isl_keep isl_dim *dim,
193         __isl_take isl_printer *p, enum isl_dim_type type, int set, int latex)
194 {
195         unsigned n = isl_dim_size(dim, type);
196         if (!latex || n != 1)
197                 p = isl_printer_print_str(p, s_open_list[latex]);
198         p = print_var_list(dim, p, type, set, latex);
199         if (!latex || n != 1)
200                 p = isl_printer_print_str(p, s_close_list[latex]);
201         return p;
202 }
203
204 static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_dim *dim,
205         __isl_take isl_printer *p)
206 {
207         if (isl_dim_size(dim, isl_dim_param) == 0)
208                 return p;
209
210         p = isl_printer_start_line(p);
211         p = isl_printer_print_str(p, "symbolic ");
212         p = print_var_list(dim, p, isl_dim_param, 0, 0);
213         p = isl_printer_print_str(p, ";");
214         p = isl_printer_end_line(p);
215         return p;
216 }
217
218 static enum isl_dim_type pos2type(__isl_keep isl_dim *dim, unsigned *pos)
219 {
220         enum isl_dim_type type;
221         unsigned n_in = isl_dim_size(dim, isl_dim_in);
222         unsigned n_out = isl_dim_size(dim, isl_dim_out);
223         unsigned nparam = isl_dim_size(dim, isl_dim_param);
224
225         if (*pos < 1 + nparam) {
226                 type = isl_dim_param;
227                 *pos -= 1;
228         } else if (*pos < 1 + nparam + n_in) {
229                 type = isl_dim_in;
230                 *pos -= 1 + nparam;
231         } else if (*pos < 1 + nparam + n_in + n_out) {
232                 type = isl_dim_out;
233                 *pos -= 1 + nparam + n_in;
234         } else {
235                 type = isl_dim_div;
236                 *pos -= 1 + nparam + n_in + n_out;
237         }
238
239         return type;
240 }
241
242 static __isl_give isl_printer *print_term(__isl_keep isl_dim *dim,
243         isl_int c, unsigned pos, __isl_take isl_printer *p, int set, int latex)
244 {
245         enum isl_dim_type type;
246
247         if (pos == 0)
248                 return isl_printer_print_isl_int(p, c);
249
250         if (isl_int_is_one(c))
251                 ;
252         else if (isl_int_is_negone(c))
253                 p = isl_printer_print_str(p, "-");
254         else
255                 p = isl_printer_print_isl_int(p, c);
256         type = pos2type(dim, &pos);
257         p = print_name(dim, p, type, pos, set, latex);
258         return p;
259 }
260
261 static __isl_give isl_printer *print_affine_of_len(__isl_keep isl_dim *dim,
262         __isl_take isl_printer *p, isl_int *c, int len, int set)
263 {
264         int i;
265         int first;
266
267         for (i = 0, first = 1; i < len; ++i) {
268                 int flip = 0;
269                 if (isl_int_is_zero(c[i]))
270                         continue;
271                 if (!first) {
272                         if (isl_int_is_neg(c[i])) {
273                                 flip = 1;
274                                 isl_int_neg(c[i], c[i]);
275                                 p = isl_printer_print_str(p, " - ");
276                         } else 
277                                 p = isl_printer_print_str(p, " + ");
278                 }
279                 first = 0;
280                 p = print_term(dim, c[i], i, p, set, 0);
281                 if (flip)
282                         isl_int_neg(c[i], c[i]);
283         }
284         if (first)
285                 p = isl_printer_print_str(p, "0");
286         return p;
287 }
288
289 static __isl_give isl_printer *print_affine(__isl_keep isl_basic_map *bmap,
290         __isl_keep isl_dim *dim, __isl_take isl_printer *p, isl_int *c, int set)
291 {
292         unsigned len = 1 + isl_basic_map_total_dim(bmap);
293         return print_affine_of_len(dim, p, c, len, set);
294 }
295
296 static __isl_give isl_printer *print_constraint(struct isl_basic_map *bmap,
297         __isl_keep isl_dim *dim, __isl_take isl_printer *p,
298         isl_int *c, int last, const char *op, int first_constraint, int set,
299         int latex)
300 {
301         if (!first_constraint)
302                 p = isl_printer_print_str(p, s_and[latex]);
303
304         isl_int_abs(c[last], c[last]);
305
306         p = print_term(dim, c[last], last, p, set, latex);
307
308         p = isl_printer_print_str(p, " ");
309         p = isl_printer_print_str(p, op);
310         p = isl_printer_print_str(p, " ");
311
312         isl_int_set_si(c[last], 0);
313         p = print_affine(bmap, dim, p, c, set);
314
315         return p;
316 }
317
318 static __isl_give isl_printer *print_constraints(__isl_keep isl_basic_map *bmap,
319         __isl_keep isl_dim *dim, __isl_take isl_printer *p, int set, int latex)
320 {
321         int i;
322         struct isl_vec *c;
323         unsigned total = isl_basic_map_total_dim(bmap);
324
325         c = isl_vec_alloc(bmap->ctx, 1 + total);
326         if (!c)
327                 goto error;
328
329         for (i = bmap->n_eq - 1; i >= 0; --i) {
330                 int l = isl_seq_last_non_zero(bmap->eq[i], 1 + total);
331                 isl_assert(bmap->ctx, l >= 0, goto error);
332                 if (isl_int_is_neg(bmap->eq[i][l]))
333                         isl_seq_cpy(c->el, bmap->eq[i], 1 + total);
334                 else
335                         isl_seq_neg(c->el, bmap->eq[i], 1 + total);
336                 p = print_constraint(bmap, dim, p, c->el, l,
337                                     "=", i == bmap->n_eq - 1, set, latex);
338         }
339         for (i = 0; i < bmap->n_ineq; ++i) {
340                 int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total);
341                 int s;
342                 const char *op;
343                 isl_assert(bmap->ctx, l >= 0, goto error);
344                 s = isl_int_sgn(bmap->ineq[i][l]);
345                 if (s < 0)
346                         isl_seq_cpy(c->el, bmap->ineq[i], 1 + total);
347                 else
348                         isl_seq_neg(c->el, bmap->ineq[i], 1 + total);
349                 op = s < 0 ? s_le[latex] : s_ge[latex];
350                 p = print_constraint(bmap, dim, p, c->el, l,
351                                         op, !bmap->n_eq && !i, set, latex);
352         }
353
354         isl_vec_free(c);
355
356         return p;
357 error:
358         isl_printer_free(p);
359         return NULL;
360 }
361
362 static __isl_give isl_printer *print_omega_constraints(
363         __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int set)
364 {
365         if (bmap->n_eq + bmap->n_ineq == 0)
366                 return p;
367
368         p = isl_printer_print_str(p, ": ");
369         if (bmap->n_div > 0) {
370                 int i;
371                 p = isl_printer_print_str(p, "exists (");
372                 for (i = 0; i < bmap->n_div; ++i) {
373                         if (i)
374                                 p = isl_printer_print_str(p, ", ");
375                         p = print_name(bmap->dim, p, isl_dim_div, i, 0, 0);
376                 }
377                 p = isl_printer_print_str(p, ": ");
378         }
379         p = print_constraints(bmap, bmap->dim, p, set, 0);
380         if (bmap->n_div > 0)
381                 p = isl_printer_print_str(p, ")");
382         return p;
383 }
384
385 static __isl_give isl_printer *basic_map_print_omega(
386         __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
387 {
388         p = isl_printer_print_str(p, "{ [");
389         p = print_var_list(bmap->dim, p, isl_dim_in, 0, 0);
390         p = isl_printer_print_str(p, "] -> [");
391         p = print_var_list(bmap->dim, p, isl_dim_out, 0, 0);
392         p = isl_printer_print_str(p, "] ");
393         p = print_omega_constraints(bmap, p, 0);
394         p = isl_printer_print_str(p, " }");
395         return p;
396 }
397
398 static __isl_give isl_printer *isl_basic_map_print_omega(
399         __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p)
400 {
401         p = print_omega_parameters(bmap->dim, p);
402
403         p = isl_printer_start_line(p);
404         p = basic_map_print_omega(bmap, p);
405         p = isl_printer_end_line(p);
406         return p;
407 }
408
409 static __isl_give isl_printer *basic_set_print_omega(
410         __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
411 {
412         p = isl_printer_print_str(p, "{ [");
413         p = print_var_list(bset->dim, p, isl_dim_set, 1, 0);
414         p = isl_printer_print_str(p, "] ");
415         p = print_omega_constraints((isl_basic_map *)bset, p, 1);
416         p = isl_printer_print_str(p, " }");
417         return p;
418 }
419
420 static __isl_give isl_printer *isl_basic_set_print_omega(
421         __isl_keep isl_basic_set *bset, __isl_take isl_printer *p)
422 {
423         p = print_omega_parameters(bset->dim, p);
424
425         p = isl_printer_start_line(p);
426         p = basic_set_print_omega(bset, p);
427         p = isl_printer_end_line(p);
428         return p;
429 }
430
431 static __isl_give isl_printer *isl_map_print_omega(__isl_keep isl_map *map,
432         __isl_take isl_printer *p)
433 {
434         int i;
435
436         p = print_omega_parameters(map->dim, p);
437
438         p = isl_printer_start_line(p);
439         for (i = 0; i < map->n; ++i) {
440                 if (i)
441                         p = isl_printer_print_str(p, " union ");
442                 p = basic_map_print_omega(map->p[i], p);
443         }
444         p = isl_printer_end_line(p);
445         return p;
446 }
447
448 static __isl_give isl_printer *isl_set_print_omega(__isl_keep isl_set *set,
449         __isl_take isl_printer *p)
450 {
451         int i;
452
453         p = print_omega_parameters(set->dim, p);
454
455         p = isl_printer_start_line(p);
456         for (i = 0; i < set->n; ++i) {
457                 if (i)
458                         p = isl_printer_print_str(p, " union ");
459                 p = basic_set_print_omega(set->p[i], p);
460         }
461         p = isl_printer_end_line(p);
462         return p;
463 }
464
465 static __isl_give isl_printer *print_disjunct(__isl_keep isl_basic_map *bmap,
466         __isl_keep isl_dim *dim, __isl_take isl_printer *p, int set, int latex)
467 {
468         if (bmap->n_div > 0) {
469                 int i;
470                 p = isl_printer_print_str(p, s_open_exists[latex]);
471                 for (i = 0; i < bmap->n_div; ++i) {
472                         if (i)
473                                 p = isl_printer_print_str(p, ", ");
474                         p = print_name(dim, p, isl_dim_div, i, 0, latex);
475                         if (latex || isl_int_is_zero(bmap->div[i][0]))
476                                 continue;
477                         p = isl_printer_print_str(p, " = [(");
478                         p = print_affine(bmap, dim, p, bmap->div[i] + 1, set);
479                         p = isl_printer_print_str(p, ")/");
480                         p = isl_printer_print_isl_int(p, bmap->div[i][0]);
481                         p = isl_printer_print_str(p, "]");
482                 }
483                 p = isl_printer_print_str(p, ": ");
484         }
485
486         p = print_constraints(bmap, dim, p, set, latex);
487
488         if (bmap->n_div > 0)
489                 p = isl_printer_print_str(p, s_close_exists[latex]);
490         return p;
491 }
492
493 static __isl_give isl_printer *isl_basic_map_print_isl(
494         __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int latex)
495 {
496         int i;
497
498         p = isl_printer_start_line(p);
499         if (isl_basic_map_dim(bmap, isl_dim_param) > 0) {
500                 p = print_tuple(bmap->dim, p, isl_dim_param, 0, latex);
501                 p = isl_printer_print_str(p, " -> ");
502         }
503         p = isl_printer_print_str(p, "{ ");
504         p = print_tuple(bmap->dim, p, isl_dim_in, 0, latex);
505         p = isl_printer_print_str(p, " -> ");
506         p = print_tuple(bmap->dim, p, isl_dim_out, 0, latex);
507         p = isl_printer_print_str(p, " : ");
508         p = print_disjunct(bmap, bmap->dim, p, 0, latex);
509         p = isl_printer_print_str(p, " }");
510         p = isl_printer_end_line(p);
511         return p;
512 }
513
514 static __isl_give isl_printer *isl_basic_set_print_isl(
515         __isl_keep isl_basic_set *bset, __isl_take isl_printer *p, int latex)
516 {
517         int i;
518
519         p = isl_printer_start_line(p);
520         if (isl_basic_set_dim(bset, isl_dim_param) > 0) {
521                 p = print_tuple(bset->dim, p, isl_dim_param, 0, latex);
522                 p = isl_printer_print_str(p, " -> ");
523         }
524         p = isl_printer_print_str(p, "{ ");
525         p = print_tuple(bset->dim, p, isl_dim_set, 1, latex);
526         p = isl_printer_print_str(p, " : ");
527         p = print_disjunct((isl_basic_map *)bset, bset->dim, p, 1, latex);
528         p = isl_printer_print_str(p, " }");
529         p = isl_printer_end_line(p);
530         return p;
531 }
532
533 static __isl_give isl_printer *print_disjuncts(__isl_keep isl_map *map,
534         __isl_take isl_printer *p, int set, int latex)
535 {
536         int i;
537
538         if (isl_map_fast_is_universe(map))
539                 return p;
540
541         p = isl_printer_print_str(p, s_such_that[latex]);
542         if (map->n == 0)
543                 p = isl_printer_print_str(p, "1 = 0");
544         for (i = 0; i < map->n; ++i) {
545                 if (i)
546                         p = isl_printer_print_str(p, s_or[latex]);
547                 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
548                         p = isl_printer_print_str(p, "(");
549                 p = print_disjunct(map->p[i], map->dim, p, set, latex);
550                 if (map->n > 1 && map->p[i]->n_eq + map->p[i]->n_ineq > 1)
551                         p = isl_printer_print_str(p, ")");
552         }
553         return p;
554 }
555
556 static __isl_give isl_printer *isl_map_print_isl(__isl_keep isl_map *map,
557         __isl_take isl_printer *p, int latex)
558 {
559         if (isl_map_dim(map, isl_dim_param) > 0) {
560                 p = print_tuple(map->dim, p, isl_dim_param, 0, latex);
561                 p = isl_printer_print_str(p, s_to[latex]);
562         }
563         p = isl_printer_print_str(p, s_open_set[latex]);
564         p = print_tuple(map->dim, p, isl_dim_in, 0, latex);
565         p = isl_printer_print_str(p, s_to[latex]);
566         p = print_tuple(map->dim, p, isl_dim_out, 0, latex);
567         p = print_disjuncts(map, p, 0, latex);
568         p = isl_printer_print_str(p, s_close_set[latex]);
569         return p;
570 }
571
572 static __isl_give isl_printer *isl_set_print_isl(__isl_keep isl_set *set,
573         __isl_take isl_printer *p, int latex)
574 {
575         int i;
576
577         if (isl_set_dim(set, isl_dim_param) > 0) {
578                 p = print_tuple(set->dim, p, isl_dim_param, 0, latex);
579                 p = isl_printer_print_str(p, " -> ");
580         }
581         p = isl_printer_print_str(p, "{ ");
582         p = print_tuple(set->dim, p, isl_dim_set, 1, latex);
583         p = print_disjuncts((isl_map *)set, p, 1, latex);
584         p = isl_printer_print_str(p, " }");
585         return p;
586 }
587
588 __isl_give isl_printer *isl_printer_print_basic_map(__isl_take isl_printer *p,
589         __isl_keep isl_basic_map *bmap)
590 {
591         if (!p || !bmap)
592                 goto error;
593         if (p->output_format == ISL_FORMAT_ISL)
594                 return isl_basic_map_print_isl(bmap, p, 0);
595         else if (p->output_format == ISL_FORMAT_OMEGA)
596                 return isl_basic_map_print_omega(bmap, p);
597         isl_assert(bmap->ctx, 0, goto error);
598 error:
599         isl_printer_free(p);
600         return NULL;
601 }
602
603 void isl_basic_map_print(__isl_keep isl_basic_map *bmap, FILE *out, int indent,
604         const char *prefix, const char *suffix, unsigned output_format)
605 {
606         isl_printer *printer;
607
608         if (!bmap)
609                 return;
610
611         printer = isl_printer_to_file(bmap->ctx, out);
612         printer = isl_printer_set_indent(printer, indent);
613         printer = isl_printer_set_prefix(printer, prefix);
614         printer = isl_printer_set_suffix(printer, suffix);
615         printer = isl_printer_set_output_format(printer, output_format);
616         isl_printer_print_basic_map(printer, bmap);
617
618         isl_printer_free(printer);
619 }
620
621 __isl_give isl_printer *isl_printer_print_basic_set(__isl_take isl_printer *p,
622         __isl_keep isl_basic_set *bset)
623 {
624         if (!p || !bset)
625                 goto error;
626
627         if (p->output_format == ISL_FORMAT_ISL)
628                 return isl_basic_set_print_isl(bset, p, 0);
629         else if (p->output_format == ISL_FORMAT_POLYLIB)
630                 return isl_basic_set_print_polylib(bset, p);
631         else if (p->output_format == ISL_FORMAT_POLYLIB_CONSTRAINTS)
632                 return bset_print_constraints_polylib(bset, p);
633         else if (p->output_format == ISL_FORMAT_OMEGA)
634                 return isl_basic_set_print_omega(bset, p);
635         isl_assert(p->ctx, 0, goto error);
636 error:
637         isl_printer_free(p);
638         return NULL;
639 }
640
641 void isl_basic_set_print(struct isl_basic_set *bset, FILE *out, int indent,
642         const char *prefix, const char *suffix, unsigned output_format)
643 {
644         isl_printer *printer;
645
646         if (!bset)
647                 return;
648
649         printer = isl_printer_to_file(bset->ctx, out);
650         printer = isl_printer_set_indent(printer, indent);
651         printer = isl_printer_set_prefix(printer, prefix);
652         printer = isl_printer_set_suffix(printer, suffix);
653         printer = isl_printer_set_output_format(printer, output_format);
654         isl_printer_print_basic_set(printer, bset);
655
656         isl_printer_free(printer);
657 }
658
659 __isl_give isl_printer *isl_printer_print_set(__isl_take isl_printer *p,
660         __isl_keep isl_set *set)
661 {
662         if (!p || !set)
663                 goto error;
664         if (p->output_format == ISL_FORMAT_ISL)
665                 return isl_set_print_isl(set, p, 0);
666         else if (p->output_format == ISL_FORMAT_POLYLIB)
667                 return isl_set_print_polylib(set, p);
668         else if (p->output_format == ISL_FORMAT_OMEGA)
669                 return isl_set_print_omega(set, p);
670         isl_assert(set->ctx, 0, goto error);
671 error:
672         isl_printer_free(p);
673         return NULL;
674 }
675
676 void isl_set_print(struct isl_set *set, FILE *out, int indent,
677         unsigned output_format)
678 {
679         isl_printer *printer;
680
681         if (!set)
682                 return;
683
684         printer = isl_printer_to_file(set->ctx, out);
685         printer = isl_printer_set_indent(printer, indent);
686         printer = isl_printer_set_output_format(printer, output_format);
687         printer = isl_printer_print_set(printer, set);
688
689         isl_printer_free(printer);
690 }
691
692 __isl_give isl_printer *isl_printer_print_map(__isl_take isl_printer *p,
693         __isl_keep isl_map *map)
694 {
695         if (!p || !map)
696                 goto error;
697
698         if (p->output_format == ISL_FORMAT_ISL)
699                 return isl_map_print_isl(map, p, 0);
700         else if (p->output_format == ISL_FORMAT_POLYLIB)
701                 return isl_map_print_polylib(map, p);
702         else if (p->output_format == ISL_FORMAT_OMEGA)
703                 return isl_map_print_omega(map, p);
704         else if (p->output_format == ISL_FORMAT_LATEX)
705                 return isl_map_print_isl(map, p, 1);
706         isl_assert(map->ctx, 0, goto error);
707 error:
708         isl_printer_free(p);
709         return NULL;
710 }
711
712 void isl_map_print(__isl_keep isl_map *map, FILE *out, int indent,
713         unsigned output_format)
714 {
715         isl_printer *printer;
716
717         if (!map)
718                 return;
719
720         printer = isl_printer_to_file(map->ctx, out);
721         printer = isl_printer_set_indent(printer, indent);
722         printer = isl_printer_set_output_format(printer, output_format);
723         printer = isl_printer_print_map(printer, map);
724
725         isl_printer_free(printer);
726 }
727
728 static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec)
729 {
730         int i;
731         int n;
732
733         for (i = 0, n = 0; i < rec->n; ++i)
734                 if (!isl_upoly_is_zero(rec->p[i]))
735                         ++n;
736
737         return n;
738 }
739
740 static __isl_give isl_printer *print_div(__isl_keep isl_dim *dim,
741         __isl_keep isl_mat *div, int pos, __isl_take isl_printer *p)
742 {
743         int c = p->output_format == ISL_FORMAT_C;
744         p = isl_printer_print_str(p, c ? "floord(" : "[(");
745         p = print_affine_of_len(dim, p, div->row[pos] + 1, div->n_col - 1, 1);
746         p = isl_printer_print_str(p, c ? ", " : ")/");
747         p = isl_printer_print_isl_int(p, div->row[pos][0]);
748         p = isl_printer_print_str(p, c ? ")" : "]");
749         return p;
750 }
751
752 static __isl_give isl_printer *upoly_print_cst(__isl_keep struct isl_upoly *up,
753         __isl_take isl_printer *p, int first)
754 {
755         struct isl_upoly_cst *cst;
756         int neg;
757
758         cst = isl_upoly_as_cst(up);
759         if (!cst)
760                 goto error;
761         neg = !first && isl_int_is_neg(cst->n);
762         if (!first)
763                 p = isl_printer_print_str(p, neg ? " - " :  " + ");
764         if (neg)
765                 isl_int_neg(cst->n, cst->n);
766         if (isl_int_is_zero(cst->d)) {
767                 int sgn = isl_int_sgn(cst->n);
768                 p = isl_printer_print_str(p, sgn < 0 ? "-infty" :
769                                             sgn == 0 ? "NaN" : "infty");
770         } else
771                 p = isl_printer_print_isl_int(p, cst->n);
772         if (neg)
773                 isl_int_neg(cst->n, cst->n);
774         if (!isl_int_is_zero(cst->d) && !isl_int_is_one(cst->d)) {
775                 p = isl_printer_print_str(p, "/");
776                 p = isl_printer_print_isl_int(p, cst->d);
777         }
778         return p;
779 error:
780         isl_printer_free(p);
781         return NULL;
782 }
783
784 static __isl_give isl_printer *print_base(__isl_take isl_printer *p,
785         __isl_keep isl_dim *dim, __isl_keep isl_mat *div, int var)
786 {
787         unsigned total;
788
789         total = isl_dim_total(dim);
790         if (var < total)
791                 p = print_term(dim, dim->ctx->one, 1 + var, p, 1, 0);
792         else
793                 p = print_div(dim, div, var - total, p);
794         return p;
795 }
796
797 static __isl_give isl_printer *print_pow(__isl_take isl_printer *p,
798         __isl_keep isl_dim *dim, __isl_keep isl_mat *div, int var, int exp)
799 {
800         p = print_base(p, dim, div, var);
801         if (exp == 1)
802                 return p;
803         if (p->output_format == ISL_FORMAT_C) {
804                 int i;
805                 for (i = 1; i < exp; ++i) {
806                         p = isl_printer_print_str(p, "*");
807                         p = print_base(p, dim, div, var);
808                 }
809         } else {
810                 p = isl_printer_print_str(p, "^");
811                 p = isl_printer_print_int(p, exp);
812         }
813         return p;
814 }
815
816 static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up,
817         __isl_keep isl_dim *dim, __isl_keep isl_mat *div,
818         __isl_take isl_printer *p)
819 {
820         int i, n, first;
821         struct isl_upoly_rec *rec;
822
823         if (!p || !up || !dim || !div)
824                 goto error;
825
826         if (isl_upoly_is_cst(up))
827                 return upoly_print_cst(up, p, 1);
828
829         rec = isl_upoly_as_rec(up);
830         if (!rec)
831                 goto error;
832         n = upoly_rec_n_non_zero(rec);
833         if (n > 1)
834                 p = isl_printer_print_str(p, "(");
835         for (i = 0, first = 1; i < rec->n; ++i) {
836                 if (isl_upoly_is_zero(rec->p[i]))
837                         continue;
838                 if (isl_upoly_is_negone(rec->p[i])) {
839                         if (!i)
840                                 p = isl_printer_print_str(p, "-1");
841                         else if (first)
842                                 p = isl_printer_print_str(p, "-");
843                         else
844                                 p = isl_printer_print_str(p, " - ");
845                 } else if (isl_upoly_is_cst(rec->p[i]) &&
846                                 !isl_upoly_is_one(rec->p[i]))
847                         p = upoly_print_cst(rec->p[i], p, first);
848                 else {
849                         if (!first)
850                                 p = isl_printer_print_str(p, " + ");
851                         if (i == 0 || !isl_upoly_is_one(rec->p[i]))
852                                 p = upoly_print(rec->p[i], dim, div, p);
853                 }
854                 first = 0;
855                 if (i == 0)
856                         continue;
857                 if (!isl_upoly_is_one(rec->p[i]) &&
858                     !isl_upoly_is_negone(rec->p[i]))
859                         p = isl_printer_print_str(p, " * ");
860                 p = print_pow(p, dim, div, rec->up.var, i);
861         }
862         if (n > 1)
863                 p = isl_printer_print_str(p, ")");
864         return p;
865 error:
866         isl_printer_free(p);
867         return NULL;
868 }
869
870 __isl_give isl_printer *isl_printer_print_qpolynomial(__isl_take isl_printer *p,
871         __isl_keep isl_qpolynomial *qp)
872 {
873         if (!p || !qp)
874                 goto error;
875         p = upoly_print(qp->upoly, qp->dim, qp->div, p);
876         return p;
877 error:
878         isl_printer_free(p);
879         return NULL;
880 }
881
882 void isl_qpolynomial_print(__isl_keep isl_qpolynomial *qp, FILE *out,
883         unsigned output_format)
884 {
885         isl_printer *p;
886
887         if  (!qp)
888                 return;
889
890         isl_assert(qp->dim->ctx, output_format == ISL_FORMAT_ISL, return);
891         p = isl_printer_to_file(qp->dim->ctx, out);
892         p = isl_printer_print_qpolynomial(p, qp);
893         isl_printer_free(p);
894 }
895
896 static __isl_give isl_printer *qpolynomial_fold_print(
897         __isl_keep isl_qpolynomial_fold *fold, __isl_take isl_printer *p)
898 {
899         int i;
900
901         if (fold->type == isl_fold_min)
902                 p = isl_printer_print_str(p, "min");
903         else if (fold->type == isl_fold_max)
904                 p = isl_printer_print_str(p, "max");
905         p = isl_printer_print_str(p, "(");
906         for (i = 0; i < fold->n; ++i) {
907                 if (i)
908                         p = isl_printer_print_str(p, ", ");
909                 p = isl_printer_print_qpolynomial(p, fold->qp[i]);
910         }
911         p = isl_printer_print_str(p, ")");
912         return p;
913 }
914
915 __isl_give isl_printer *isl_printer_print_qpolynomial_fold(
916         __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
917 {
918         if  (!p || !fold)
919                 goto error;
920         p = qpolynomial_fold_print(fold, p);
921         return p;
922 error:
923         isl_printer_free(p);
924         return NULL;
925 }
926
927 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold *fold,
928         FILE *out, unsigned output_format)
929 {
930         isl_printer *p;
931
932         if (!fold)
933                 return;
934
935         isl_assert(fold->dim->ctx, output_format == ISL_FORMAT_ISL, return);
936
937         p = isl_printer_to_file(fold->dim->ctx, out);
938         p = isl_printer_print_qpolynomial_fold(p, fold);
939
940         isl_printer_free(p);
941 }
942
943 static __isl_give isl_printer *print_pw_qpolynomial_isl(
944         __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
945 {
946         int i = 0;
947
948         if (!p || !pwqp)
949                 goto error;
950
951         if (isl_dim_size(pwqp->dim, isl_dim_param) > 0) {
952                 p = print_tuple(pwqp->dim, p, isl_dim_param, 0, 0);
953                 p = isl_printer_print_str(p, " -> ");
954         }
955         p = isl_printer_print_str(p, "{ ");
956         if (pwqp->n == 0) {
957                 if (isl_dim_size(pwqp->dim, isl_dim_set) > 0) {
958                         p = print_tuple(pwqp->dim, p, isl_dim_set, 1, 0);
959                         p = isl_printer_print_str(p, " -> ");
960                 }
961                 p = isl_printer_print_str(p, "0");
962         }
963         for (i = 0; i < pwqp->n; ++i) {
964                 if (i)
965                         p = isl_printer_print_str(p, "; ");
966                 if (isl_dim_size(pwqp->p[i].set->dim, isl_dim_set) > 0) {
967                         p = print_tuple(pwqp->p[i].set->dim, p, isl_dim_set, 1, 0);
968                         p = isl_printer_print_str(p, " -> ");
969                 }
970                 p = isl_printer_print_qpolynomial(p, pwqp->p[i].qp);
971                 p = print_disjuncts((isl_map *)pwqp->p[i].set, p, 1, 0);
972         }
973         p = isl_printer_print_str(p, " }");
974         return p;
975 error:
976         isl_printer_free(p);
977         return NULL;
978 }
979
980 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial *pwqp, FILE *out,
981         unsigned output_format)
982 {
983         isl_printer *p;
984
985         if (!pwqp)
986                 return;
987
988         p = isl_printer_to_file(pwqp->dim->ctx, out);
989         p = isl_printer_set_output_format(p, output_format);
990         p = isl_printer_print_pw_qpolynomial(p, pwqp);
991
992         isl_printer_free(p);
993 }
994
995 static __isl_give isl_printer *print_pw_qpolynomial_fold_isl(
996         __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
997 {
998         int i = 0;
999
1000         if (isl_dim_size(pwf->dim, isl_dim_param) > 0) {
1001                 p = print_tuple(pwf->dim, p, isl_dim_param, 0, 0);
1002                 p = isl_printer_print_str(p, " -> ");
1003         }
1004         p = isl_printer_print_str(p, "{ ");
1005         if (pwf->n == 0) {
1006                 if (isl_dim_size(pwf->dim, isl_dim_set) > 0) {
1007                         p = print_tuple(pwf->dim, p, isl_dim_set, 0, 0);
1008                         p = isl_printer_print_str(p, " -> ");
1009                 }
1010                 p = isl_printer_print_str(p, "0");
1011         }
1012         for (i = 0; i < pwf->n; ++i) {
1013                 if (i)
1014                         p = isl_printer_print_str(p, "; ");
1015                 if (isl_dim_size(pwf->p[i].set->dim, isl_dim_set) > 0) {
1016                         p = print_tuple(pwf->p[i].set->dim, p, isl_dim_set, 0, 0);
1017                         p = isl_printer_print_str(p, " -> ");
1018                 }
1019                 p = qpolynomial_fold_print(pwf->p[i].fold, p);
1020                 p = print_disjuncts((isl_map *)pwf->p[i].set, p, 1, 0);
1021         }
1022         p = isl_printer_print_str(p, " }");
1023         return p;
1024 }
1025
1026 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1027         __isl_keep isl_basic_set *bset, isl_int *c);
1028
1029 static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p,
1030         __isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos)
1031 {
1032         if (type == isl_dim_div) {
1033                 p = isl_printer_print_str(p, "floord(");
1034                 p = print_affine_c(p, bset, bset->div[pos] + 1);
1035                 p = isl_printer_print_str(p, ", ");
1036                 p = isl_printer_print_isl_int(p, bset->div[pos][0]);
1037                 p = isl_printer_print_str(p, ")");
1038         } else {
1039                 const char *name;
1040
1041                 name = isl_dim_get_name(bset->dim, type, pos);
1042                 if (!name)
1043                         name = "UNNAMED";
1044                 p = isl_printer_print_str(p, name);
1045         }
1046         return p;
1047 }
1048
1049 static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p,
1050         __isl_keep isl_basic_set *bset, isl_int c, unsigned pos)
1051 {
1052         enum isl_dim_type type;
1053         unsigned nparam = isl_basic_set_dim(bset, isl_dim_param);
1054
1055         if (pos == 0)
1056                 return isl_printer_print_isl_int(p, c);
1057
1058         if (isl_int_is_one(c))
1059                 ;
1060         else if (isl_int_is_negone(c))
1061                 p = isl_printer_print_str(p, "-");
1062         else {
1063                 p = isl_printer_print_isl_int(p, c);
1064                 p = isl_printer_print_str(p, "*");
1065         }
1066         type = pos2type(bset->dim, &pos);
1067         p = print_name_c(p, bset, type, pos);
1068         return p;
1069 }
1070
1071 static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p,
1072         __isl_keep isl_basic_set *bset, isl_int *c)
1073 {
1074         int i;
1075         int first;
1076         unsigned len = 1 + isl_basic_set_total_dim(bset);
1077
1078         for (i = 0, first = 1; i < len; ++i) {
1079                 int flip = 0;
1080                 if (isl_int_is_zero(c[i]))
1081                         continue;
1082                 if (!first) {
1083                         if (isl_int_is_neg(c[i])) {
1084                                 flip = 1;
1085                                 isl_int_neg(c[i], c[i]);
1086                                 p = isl_printer_print_str(p, " - ");
1087                         } else 
1088                                 p = isl_printer_print_str(p, " + ");
1089                 }
1090                 first = 0;
1091                 p = print_term(bset->dim, c[i], i, p, 1, 0);
1092                 if (flip)
1093                         isl_int_neg(c[i], c[i]);
1094         }
1095         if (first)
1096                 p = isl_printer_print_str(p, "0");
1097         return p;
1098 }
1099
1100 static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p,
1101         __isl_keep isl_basic_set *bset, isl_int *c, const char *op, int first)
1102 {
1103         if (!first)
1104                 p = isl_printer_print_str(p, " && ");
1105
1106         p = print_affine_c(p, bset, c);
1107         p = isl_printer_print_str(p, " ");
1108         p = isl_printer_print_str(p, op);
1109         p = isl_printer_print_str(p, " 0");
1110         return p;
1111 }
1112
1113 static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p,
1114         __isl_keep isl_basic_set *bset)
1115 {
1116         int i;
1117
1118         for (i = 0; i < bset->n_eq; ++i)
1119                 p = print_constraint_c(p, bset, bset->eq[i], "==", !i);
1120         for (i = 0; i < bset->n_ineq; ++i)
1121                 p = print_constraint_c(p, bset, bset->ineq[i], ">=",
1122                                         !bset->n_eq && !i);
1123         return p;
1124 }
1125
1126 static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p,
1127         __isl_keep isl_set *set)
1128 {
1129         int i;
1130
1131         if (set->n == 0)
1132                 p = isl_printer_print_str(p, "0");
1133
1134         for (i = 0; i < set->n; ++i) {
1135                 if (i)
1136                         p = isl_printer_print_str(p, " || ");
1137                 if (set->n > 1)
1138                         p = isl_printer_print_str(p, "(");
1139                 p = print_basic_set_c(p, set->p[i]);
1140                 if (set->n > 1)
1141                         p = isl_printer_print_str(p, ")");
1142         }
1143         return p;
1144 }
1145
1146 static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p,
1147         __isl_keep isl_qpolynomial *qp)
1148 {
1149         isl_int den;
1150
1151         isl_int_init(den);
1152         isl_qpolynomial_get_den(qp, &den);
1153         if (!isl_int_is_one(den)) {
1154                 isl_qpolynomial *f;
1155                 p = isl_printer_print_str(p, "(");
1156                 qp = isl_qpolynomial_copy(qp);
1157                 f = isl_qpolynomial_rat_cst(isl_dim_copy(qp->dim),
1158                                                 den, qp->dim->ctx->one);
1159                 qp = isl_qpolynomial_mul(qp, f);
1160         }
1161         if (qp)
1162                 p = upoly_print(qp->upoly, qp->dim, qp->div, p);
1163         if (!isl_int_is_one(den)) {
1164                 p = isl_printer_print_str(p, ")/");
1165                 p = isl_printer_print_isl_int(p, den);
1166                 isl_qpolynomial_free(qp);
1167         }
1168         isl_int_clear(den);
1169         return p;
1170 }
1171
1172 static __isl_give isl_printer *print_pw_qpolynomial_c(
1173         __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwpq)
1174 {
1175         int i;
1176
1177         if (pwpq->n == 1 && isl_set_fast_is_universe(pwpq->p[0].set))
1178                 return print_qpolynomial_c(p, pwpq->p[0].qp);
1179
1180         for (i = 0; i < pwpq->n; ++i) {
1181                 p = isl_printer_print_str(p, "(");
1182                 p = print_set_c(p, pwpq->p[i].set);
1183                 p = isl_printer_print_str(p, ") ? (");
1184                 p = print_qpolynomial_c(p, pwpq->p[i].qp);
1185                 p = isl_printer_print_str(p, ") : ");
1186         }
1187
1188         p = isl_printer_print_str(p, "0");
1189         return p;
1190 }
1191
1192 __isl_give isl_printer *isl_printer_print_pw_qpolynomial(
1193         __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial *pwqp)
1194 {
1195         if (!p || !pwqp)
1196                 goto error;
1197
1198         if (p->output_format == ISL_FORMAT_ISL)
1199                 return print_pw_qpolynomial_isl(p, pwqp);
1200         else if (p->output_format == ISL_FORMAT_C)
1201                 return print_pw_qpolynomial_c(p, pwqp);
1202         isl_assert(p->ctx, 0, goto error);
1203 error:
1204         isl_printer_free(p);
1205         return NULL;
1206 }
1207
1208 static __isl_give isl_printer *print_qpolynomial_fold_c(
1209         __isl_take isl_printer *p, __isl_keep isl_qpolynomial_fold *fold)
1210 {
1211         int i;
1212
1213         for (i = 0; i < fold->n - 1; ++i)
1214                 if (fold->type == isl_fold_min)
1215                         p = isl_printer_print_str(p, "min(");
1216                 else if (fold->type == isl_fold_max)
1217                         p = isl_printer_print_str(p, "max(");
1218
1219         for (i = 0; i < fold->n; ++i) {
1220                 if (i)
1221                         p = isl_printer_print_str(p, ", ");
1222                 p = print_qpolynomial_c(p, fold->qp[i]);
1223                 if (i)
1224                         p = isl_printer_print_str(p, ")");
1225         }
1226         return p;
1227 }
1228
1229 static __isl_give isl_printer *print_pw_qpolynomial_fold_c(
1230         __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1231 {
1232         int i;
1233
1234         if (pwf->n == 1 && isl_set_fast_is_universe(pwf->p[0].set))
1235                 return print_qpolynomial_fold_c(p, pwf->p[0].fold);
1236
1237         for (i = 0; i < pwf->n; ++i) {
1238                 p = isl_printer_print_str(p, "(");
1239                 p = print_set_c(p, pwf->p[i].set);
1240                 p = isl_printer_print_str(p, ") ? (");
1241                 p = print_qpolynomial_fold_c(p, pwf->p[i].fold);
1242                 p = isl_printer_print_str(p, ") : ");
1243         }
1244
1245         p = isl_printer_print_str(p, "0");
1246         return p;
1247 }
1248
1249 __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold(
1250         __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf)
1251 {
1252         if (!p || !pwf)
1253                 goto error;
1254
1255         if (p->output_format == ISL_FORMAT_ISL)
1256                 return print_pw_qpolynomial_fold_isl(p, pwf);
1257         else if (p->output_format == ISL_FORMAT_C)
1258                 return print_pw_qpolynomial_fold_c(p, pwf);
1259         isl_assert(p->ctx, 0, goto error);
1260 error:
1261         isl_printer_free(p);
1262         return NULL;
1263 }
1264
1265 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold *pwf,
1266         FILE *out, unsigned output_format)
1267 {
1268         isl_printer *p;
1269
1270         if (!pwf)
1271                 return;
1272
1273         p = isl_printer_to_file(pwf->dim->ctx, out);
1274         p = isl_printer_set_output_format(p, output_format);
1275         p = isl_printer_print_pw_qpolynomial_fold(p, pwf);
1276
1277         isl_printer_free(p);
1278 }