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
16 #include <isl_polynomial_private.h>
17 #include <isl_printer_private.h>
19 static __isl_give isl_printer
*print_constraint_polylib(
20 struct isl_basic_map
*bmap
, int ineq
, int n
, __isl_take isl_printer
*p
)
23 unsigned n_in
= isl_basic_map_dim(bmap
, isl_dim_in
);
24 unsigned n_out
= isl_basic_map_dim(bmap
, isl_dim_out
);
25 unsigned nparam
= isl_basic_map_dim(bmap
, isl_dim_param
);
26 isl_int
*c
= ineq
? bmap
->ineq
[n
] : bmap
->eq
[n
];
28 p
= isl_printer_start_line(p
);
29 p
= isl_printer_print_int(p
, ineq
);
30 for (i
= 0; i
< n_out
; ++i
) {
31 p
= isl_printer_print_str(p
, " ");
32 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+i
]);
34 for (i
= 0; i
< n_in
; ++i
) {
35 p
= isl_printer_print_str(p
, " ");
36 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+i
]);
38 for (i
= 0; i
< bmap
->n_div
; ++i
) {
39 p
= isl_printer_print_str(p
, " ");
40 p
= isl_printer_print_isl_int(p
, c
[1+nparam
+n_in
+n_out
+i
]);
42 for (i
= 0; i
< nparam
; ++i
) {
43 p
= isl_printer_print_str(p
, " ");
44 p
= isl_printer_print_isl_int(p
, c
[1+i
]);
46 p
= isl_printer_print_str(p
, " ");
47 p
= isl_printer_print_isl_int(p
, c
[0]);
48 p
= isl_printer_end_line(p
);
52 static __isl_give isl_printer
*print_constraints_polylib(
53 struct isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
57 p
= isl_printer_set_isl_int_width(p
, 5);
59 for (i
= 0; i
< bmap
->n_eq
; ++i
)
60 p
= print_constraint_polylib(bmap
, 0, i
, p
);
61 for (i
= 0; i
< bmap
->n_ineq
; ++i
)
62 p
= print_constraint_polylib(bmap
, 1, i
, p
);
67 static __isl_give isl_printer
*bset_print_constraints_polylib(
68 struct isl_basic_set
*bset
, __isl_take isl_printer
*p
)
70 return print_constraints_polylib((struct isl_basic_map
*)bset
, p
);
73 static __isl_give isl_printer
*isl_basic_map_print_polylib(
74 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
76 unsigned total
= isl_basic_map_total_dim(bmap
);
77 p
= isl_printer_start_line(p
);
78 p
= isl_printer_print_int(p
, bmap
->n_eq
+ bmap
->n_ineq
);
79 p
= isl_printer_print_str(p
, " ");
80 p
= isl_printer_print_int(p
, 1 + total
+ 1);
81 p
= isl_printer_end_line(p
);
82 return print_constraints_polylib(bmap
, p
);
85 static __isl_give isl_printer
*isl_basic_set_print_polylib(
86 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
88 return isl_basic_map_print_polylib((struct isl_basic_map
*)bset
, p
);
91 static __isl_give isl_printer
*isl_map_print_polylib(__isl_keep isl_map
*map
,
92 __isl_take isl_printer
*p
)
96 p
= isl_printer_start_line(p
);
97 p
= isl_printer_print_int(p
, map
->n
);
98 p
= isl_printer_end_line(p
);
99 for (i
= 0; i
< map
->n
; ++i
) {
100 p
= isl_printer_start_line(p
);
101 p
= isl_printer_end_line(p
);
102 p
= isl_basic_map_print_polylib(map
->p
[i
], p
);
107 static __isl_give isl_printer
*isl_set_print_polylib(__isl_keep isl_set
*set
,
108 __isl_take isl_printer
*p
)
110 return isl_map_print_polylib((struct isl_map
*)set
, p
);
113 static int count_same_name(__isl_keep isl_dim
*dim
,
114 enum isl_dim_type type
, unsigned pos
, const char *name
)
120 for (t
= isl_dim_param
; t
<= type
&& t
<= isl_dim_out
; ++t
) {
121 s
= t
== type
? pos
: isl_dim_size(dim
, t
);
122 for (p
= 0; p
< s
; ++p
) {
123 const char *n
= isl_dim_get_name(dim
, t
, p
);
124 if (n
&& !strcmp(n
, name
))
131 static __isl_give isl_printer
*print_name(__isl_keep isl_dim
*dim
,
132 __isl_take isl_printer
*p
, enum isl_dim_type type
, unsigned pos
, int set
)
138 name
= type
== isl_dim_div
? NULL
: isl_dim_get_name(dim
, type
, pos
);
142 if (type
== isl_dim_param
)
144 else if (type
== isl_dim_div
)
146 else if (set
|| type
== isl_dim_in
)
150 snprintf(buffer
, sizeof(buffer
), "%s%d", prefix
, pos
);
153 primes
= count_same_name(dim
, name
== buffer
? isl_dim_div
: type
,
155 p
= isl_printer_print_str(p
, name
);
157 p
= isl_printer_print_str(p
, "'");
161 static __isl_give isl_printer
*print_var_list(__isl_keep isl_dim
*dim
,
162 __isl_take isl_printer
*p
, enum isl_dim_type type
, int set
)
166 for (i
= 0; i
< isl_dim_size(dim
, type
); ++i
) {
168 p
= isl_printer_print_str(p
, ", ");
169 p
= print_name(dim
, p
, type
, i
, set
);
174 static __isl_give isl_printer
*print_tuple(__isl_keep isl_dim
*dim
,
175 __isl_take isl_printer
*p
, enum isl_dim_type type
, int set
)
177 p
= isl_printer_print_str(p
, "[");
178 p
= print_var_list(dim
, p
, type
, set
);
179 p
= isl_printer_print_str(p
, "]");
183 static __isl_give isl_printer
*print_omega_parameters(__isl_keep isl_dim
*dim
,
184 __isl_take isl_printer
*p
)
186 if (isl_dim_size(dim
, isl_dim_param
) == 0)
189 p
= isl_printer_start_line(p
);
190 p
= isl_printer_print_str(p
, "symbolic ");
191 p
= print_var_list(dim
, p
, isl_dim_param
, 0);
192 p
= isl_printer_print_str(p
, ";");
193 p
= isl_printer_end_line(p
);
197 static __isl_give isl_printer
*print_term(__isl_keep isl_dim
*dim
,
198 isl_int c
, int pos
, __isl_take isl_printer
*p
, int set
)
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
);
206 return isl_printer_print_isl_int(p
, c
);
208 if (isl_int_is_one(c
))
210 else if (isl_int_is_negone(c
))
211 p
= isl_printer_print_str(p
, "-");
213 p
= isl_printer_print_isl_int(p
, c
);
214 if (pos
< 1 + nparam
) {
215 type
= isl_dim_param
;
217 } else if (pos
< 1 + nparam
+ n_in
) {
220 } else if (pos
< 1 + nparam
+ n_in
+ n_out
) {
222 pos
-= 1 + nparam
+ n_in
;
225 pos
-= 1 + nparam
+ n_in
+ n_out
;
227 p
= print_name(dim
, p
, type
, pos
, set
);
231 static __isl_give isl_printer
*print_affine_of_len(__isl_keep isl_dim
*dim
,
232 __isl_take isl_printer
*p
, isl_int
*c
, int len
, int set
)
237 for (i
= 0, first
= 1; i
< len
; ++i
) {
239 if (isl_int_is_zero(c
[i
]))
242 if (isl_int_is_neg(c
[i
])) {
244 isl_int_neg(c
[i
], c
[i
]);
245 p
= isl_printer_print_str(p
, " - ");
247 p
= isl_printer_print_str(p
, " + ");
250 p
= print_term(dim
, c
[i
], i
, p
, set
);
252 isl_int_neg(c
[i
], c
[i
]);
255 p
= isl_printer_print_str(p
, "0");
259 static __isl_give isl_printer
*print_affine(__isl_keep isl_basic_map
*bmap
,
260 __isl_keep isl_dim
*dim
, __isl_take isl_printer
*p
, isl_int
*c
, int set
)
262 unsigned len
= 1 + isl_basic_map_total_dim(bmap
);
263 return print_affine_of_len(dim
, p
, c
, len
, set
);
266 static __isl_give isl_printer
*print_constraint(struct isl_basic_map
*bmap
,
267 __isl_keep isl_dim
*dim
, __isl_take isl_printer
*p
,
268 isl_int
*c
, int last
, const char *op
, int first_constraint
, int set
)
270 if (!first_constraint
)
271 p
= isl_printer_print_str(p
, " and ");
273 isl_int_abs(c
[last
], c
[last
]);
275 p
= print_term(dim
, c
[last
], last
, p
, set
);
277 p
= isl_printer_print_str(p
, " ");
278 p
= isl_printer_print_str(p
, op
);
279 p
= isl_printer_print_str(p
, " ");
281 isl_int_set_si(c
[last
], 0);
282 p
= print_affine(bmap
, dim
, p
, c
, set
);
287 static __isl_give isl_printer
*print_constraints(__isl_keep isl_basic_map
*bmap
,
288 __isl_keep isl_dim
*dim
, __isl_take isl_printer
*p
, int set
)
292 unsigned total
= isl_basic_map_total_dim(bmap
);
294 c
= isl_vec_alloc(bmap
->ctx
, 1 + total
);
298 for (i
= bmap
->n_eq
- 1; i
>= 0; --i
) {
299 int l
= isl_seq_last_non_zero(bmap
->eq
[i
], 1 + total
);
300 isl_assert(bmap
->ctx
, l
>= 0, goto error
);
301 if (isl_int_is_neg(bmap
->eq
[i
][l
]))
302 isl_seq_cpy(c
->el
, bmap
->eq
[i
], 1 + total
);
304 isl_seq_neg(c
->el
, bmap
->eq
[i
], 1 + total
);
305 p
= print_constraint(bmap
, dim
, p
, c
->el
, l
,
306 "=", i
== bmap
->n_eq
- 1, set
);
308 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
309 int l
= isl_seq_last_non_zero(bmap
->ineq
[i
], 1 + total
);
311 isl_assert(bmap
->ctx
, l
>= 0, goto error
);
312 s
= isl_int_sgn(bmap
->ineq
[i
][l
]);
314 isl_seq_cpy(c
->el
, bmap
->ineq
[i
], 1 + total
);
316 isl_seq_neg(c
->el
, bmap
->ineq
[i
], 1 + total
);
317 p
= print_constraint(bmap
, dim
, p
, c
->el
, l
,
318 s
< 0 ? "<=" : ">=", !bmap
->n_eq
&& !i
, set
);
329 static __isl_give isl_printer
*print_omega_constraints(
330 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
, int set
)
332 if (bmap
->n_eq
+ bmap
->n_ineq
== 0)
335 p
= isl_printer_print_str(p
, ": ");
336 if (bmap
->n_div
> 0) {
338 p
= isl_printer_print_str(p
, "exists (");
339 for (i
= 0; i
< bmap
->n_div
; ++i
) {
341 p
= isl_printer_print_str(p
, ", ");
342 p
= print_name(bmap
->dim
, p
, isl_dim_div
, i
, 0);
344 p
= isl_printer_print_str(p
, ": ");
346 p
= print_constraints(bmap
, bmap
->dim
, p
, set
);
348 p
= isl_printer_print_str(p
, ")");
352 static __isl_give isl_printer
*basic_map_print_omega(
353 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
355 p
= isl_printer_print_str(p
, "{ [");
356 p
= print_var_list(bmap
->dim
, p
, isl_dim_in
, 0);
357 p
= isl_printer_print_str(p
, "] -> [");
358 p
= print_var_list(bmap
->dim
, p
, isl_dim_out
, 0);
359 p
= isl_printer_print_str(p
, "] ");
360 p
= print_omega_constraints(bmap
, p
, 0);
361 p
= isl_printer_print_str(p
, " }");
365 static __isl_give isl_printer
*isl_basic_map_print_omega(
366 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
368 p
= print_omega_parameters(bmap
->dim
, p
);
370 p
= isl_printer_start_line(p
);
371 p
= basic_map_print_omega(bmap
, p
);
372 p
= isl_printer_end_line(p
);
376 static __isl_give isl_printer
*basic_set_print_omega(
377 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
379 p
= isl_printer_print_str(p
, "{ [");
380 p
= print_var_list(bset
->dim
, p
, isl_dim_set
, 1);
381 p
= isl_printer_print_str(p
, "] ");
382 p
= print_omega_constraints((isl_basic_map
*)bset
, p
, 1);
383 p
= isl_printer_print_str(p
, " }");
387 static __isl_give isl_printer
*isl_basic_set_print_omega(
388 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
390 p
= print_omega_parameters(bset
->dim
, p
);
392 p
= isl_printer_start_line(p
);
393 p
= basic_set_print_omega(bset
, p
);
394 p
= isl_printer_end_line(p
);
398 static __isl_give isl_printer
*isl_map_print_omega(__isl_keep isl_map
*map
,
399 __isl_take isl_printer
*p
)
403 p
= print_omega_parameters(map
->dim
, p
);
405 p
= isl_printer_start_line(p
);
406 for (i
= 0; i
< map
->n
; ++i
) {
408 p
= isl_printer_print_str(p
, " union ");
409 p
= basic_map_print_omega(map
->p
[i
], p
);
411 p
= isl_printer_end_line(p
);
415 static __isl_give isl_printer
*isl_set_print_omega(__isl_keep isl_set
*set
,
416 __isl_take isl_printer
*p
)
420 p
= print_omega_parameters(set
->dim
, p
);
422 p
= isl_printer_start_line(p
);
423 for (i
= 0; i
< set
->n
; ++i
) {
425 p
= isl_printer_print_str(p
, " union ");
426 p
= basic_set_print_omega(set
->p
[i
], p
);
428 p
= isl_printer_end_line(p
);
432 static __isl_give isl_printer
*print_disjunct(__isl_keep isl_basic_map
*bmap
,
433 __isl_keep isl_dim
*dim
, __isl_take isl_printer
*p
, int set
)
435 if (bmap
->n_div
> 0) {
437 p
= isl_printer_print_str(p
, "exists (");
438 for (i
= 0; i
< bmap
->n_div
; ++i
) {
440 p
= isl_printer_print_str(p
, ", ");
441 p
= print_name(dim
, p
, isl_dim_div
, i
, 0);
442 if (isl_int_is_zero(bmap
->div
[i
][0]))
444 p
= isl_printer_print_str(p
, " = [(");
445 p
= print_affine(bmap
, dim
, p
, bmap
->div
[i
] + 1, set
);
446 p
= isl_printer_print_str(p
, ")/");
447 p
= isl_printer_print_isl_int(p
, bmap
->div
[i
][0]);
448 p
= isl_printer_print_str(p
, "]");
450 p
= isl_printer_print_str(p
, ": ");
453 p
= print_constraints(bmap
, dim
, p
, set
);
456 p
= isl_printer_print_str(p
, ")");
460 static __isl_give isl_printer
*isl_basic_map_print_isl(
461 __isl_keep isl_basic_map
*bmap
, __isl_take isl_printer
*p
)
465 p
= isl_printer_start_line(p
);
466 if (isl_basic_map_dim(bmap
, isl_dim_param
) > 0) {
467 p
= print_tuple(bmap
->dim
, p
, isl_dim_param
, 0);
468 p
= isl_printer_print_str(p
, " -> ");
470 p
= isl_printer_print_str(p
, "{ ");
471 p
= print_tuple(bmap
->dim
, p
, isl_dim_in
, 0);
472 p
= isl_printer_print_str(p
, " -> ");
473 p
= print_tuple(bmap
->dim
, p
, isl_dim_out
, 0);
474 p
= isl_printer_print_str(p
, " : ");
475 p
= print_disjunct(bmap
, bmap
->dim
, p
, 0);
476 p
= isl_printer_end_line(p
);
480 static __isl_give isl_printer
*isl_basic_set_print_isl(
481 __isl_keep isl_basic_set
*bset
, __isl_take isl_printer
*p
)
485 p
= isl_printer_start_line(p
);
486 if (isl_basic_set_dim(bset
, isl_dim_param
) > 0) {
487 p
= print_tuple(bset
->dim
, p
, isl_dim_param
, 0);
488 p
= isl_printer_print_str(p
, " -> ");
490 p
= isl_printer_print_str(p
, "{ ");
491 p
= print_tuple(bset
->dim
, p
, isl_dim_set
, 1);
492 p
= isl_printer_print_str(p
, " : ");
493 p
= print_disjunct((isl_basic_map
*)bset
, bset
->dim
, p
, 1);
494 p
= isl_printer_end_line(p
);
498 static __isl_give isl_printer
*print_disjuncts(__isl_keep isl_map
*map
,
499 __isl_take isl_printer
*p
, int set
)
503 if (isl_map_fast_is_universe(map
))
506 p
= isl_printer_print_str(p
, " : ");
508 p
= isl_printer_print_str(p
, "1 = 0");
509 for (i
= 0; i
< map
->n
; ++i
) {
511 p
= isl_printer_print_str(p
, " or ");
512 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
513 p
= isl_printer_print_str(p
, "(");
514 p
= print_disjunct(map
->p
[i
], map
->dim
, p
, set
);
515 if (map
->n
> 1 && map
->p
[i
]->n_eq
+ map
->p
[i
]->n_ineq
> 1)
516 p
= isl_printer_print_str(p
, ")");
521 static __isl_give isl_printer
*isl_map_print_isl(__isl_keep isl_map
*map
,
522 __isl_take isl_printer
*p
)
524 if (isl_map_dim(map
, isl_dim_param
) > 0) {
525 p
= print_tuple(map
->dim
, p
, isl_dim_param
, 0);
526 p
= isl_printer_print_str(p
, " -> ");
528 p
= isl_printer_print_str(p
, "{ ");
529 p
= print_tuple(map
->dim
, p
, isl_dim_in
, 0);
530 p
= isl_printer_print_str(p
, " -> ");
531 p
= print_tuple(map
->dim
, p
, isl_dim_out
, 0);
532 p
= print_disjuncts(map
, p
, 0);
533 p
= isl_printer_print_str(p
, " }");
537 static __isl_give isl_printer
*isl_set_print_isl(__isl_keep isl_set
*set
,
538 __isl_take isl_printer
*p
)
542 if (isl_set_dim(set
, isl_dim_param
) > 0) {
543 p
= print_tuple(set
->dim
, p
, isl_dim_param
, 0);
544 p
= isl_printer_print_str(p
, " -> ");
546 p
= isl_printer_print_str(p
, "{ ");
547 p
= print_tuple(set
->dim
, p
, isl_dim_set
, 1);
548 p
= print_disjuncts((isl_map
*)set
, p
, 1);
549 p
= isl_printer_print_str(p
, " }");
553 __isl_give isl_printer
*isl_printer_print_basic_map(__isl_take isl_printer
*p
,
554 __isl_keep isl_basic_map
*bmap
)
558 if (p
->output_format
== ISL_FORMAT_ISL
)
559 return isl_basic_map_print_isl(bmap
, p
);
560 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
561 return isl_basic_map_print_omega(bmap
, p
);
562 isl_assert(bmap
->ctx
, 0, goto error
);
568 void isl_basic_map_print(__isl_keep isl_basic_map
*bmap
, FILE *out
, int indent
,
569 const char *prefix
, const char *suffix
, unsigned output_format
)
571 isl_printer
*printer
;
576 printer
= isl_printer_to_file(bmap
->ctx
, out
);
577 printer
= isl_printer_set_indent(printer
, indent
);
578 printer
= isl_printer_set_prefix(printer
, prefix
);
579 printer
= isl_printer_set_suffix(printer
, suffix
);
580 printer
= isl_printer_set_output_format(printer
, output_format
);
581 isl_printer_print_basic_map(printer
, bmap
);
583 isl_printer_free(printer
);
586 __isl_give isl_printer
*isl_printer_print_basic_set(__isl_take isl_printer
*p
,
587 __isl_keep isl_basic_set
*bset
)
592 if (p
->output_format
== ISL_FORMAT_ISL
)
593 return isl_basic_set_print_isl(bset
, p
);
594 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
595 return isl_basic_set_print_polylib(bset
, p
);
596 else if (p
->output_format
== ISL_FORMAT_POLYLIB_CONSTRAINTS
)
597 return bset_print_constraints_polylib(bset
, p
);
598 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
599 return isl_basic_set_print_omega(bset
, p
);
600 isl_assert(p
->ctx
, 0, goto error
);
606 void isl_basic_set_print(struct isl_basic_set
*bset
, FILE *out
, int indent
,
607 const char *prefix
, const char *suffix
, unsigned output_format
)
609 isl_printer
*printer
;
614 printer
= isl_printer_to_file(bset
->ctx
, out
);
615 printer
= isl_printer_set_indent(printer
, indent
);
616 printer
= isl_printer_set_prefix(printer
, prefix
);
617 printer
= isl_printer_set_suffix(printer
, suffix
);
618 printer
= isl_printer_set_output_format(printer
, output_format
);
619 isl_printer_print_basic_set(printer
, bset
);
621 isl_printer_free(printer
);
624 __isl_give isl_printer
*isl_printer_print_set(__isl_take isl_printer
*p
,
625 __isl_keep isl_set
*set
)
629 if (p
->output_format
== ISL_FORMAT_ISL
)
630 return isl_set_print_isl(set
, p
);
631 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
632 return isl_set_print_polylib(set
, p
);
633 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
634 return isl_set_print_omega(set
, p
);
635 isl_assert(set
->ctx
, 0, goto error
);
641 void isl_set_print(struct isl_set
*set
, FILE *out
, int indent
,
642 unsigned output_format
)
644 isl_printer
*printer
;
649 printer
= isl_printer_to_file(set
->ctx
, out
);
650 printer
= isl_printer_set_indent(printer
, indent
);
651 printer
= isl_printer_set_output_format(printer
, output_format
);
652 printer
= isl_printer_print_set(printer
, set
);
654 isl_printer_free(printer
);
657 __isl_give isl_printer
*isl_printer_print_map(__isl_take isl_printer
*p
,
658 __isl_keep isl_map
*map
)
663 if (p
->output_format
== ISL_FORMAT_ISL
)
664 return isl_map_print_isl(map
, p
);
665 else if (p
->output_format
== ISL_FORMAT_POLYLIB
)
666 return isl_map_print_polylib(map
, p
);
667 else if (p
->output_format
== ISL_FORMAT_OMEGA
)
668 return isl_map_print_omega(map
, p
);
669 isl_assert(map
->ctx
, 0, goto error
);
675 void isl_map_print(__isl_keep isl_map
*map
, FILE *out
, int indent
,
676 unsigned output_format
)
678 isl_printer
*printer
;
683 printer
= isl_printer_to_file(map
->ctx
, out
);
684 printer
= isl_printer_set_indent(printer
, indent
);
685 printer
= isl_printer_set_output_format(printer
, output_format
);
686 printer
= isl_printer_print_map(printer
, map
);
688 isl_printer_free(printer
);
691 static int upoly_rec_n_non_zero(__isl_keep
struct isl_upoly_rec
*rec
)
696 for (i
= 0, n
= 0; i
< rec
->n
; ++i
)
697 if (!isl_upoly_is_zero(rec
->p
[i
]))
703 static __isl_give isl_printer
*print_div(__isl_keep isl_dim
*dim
,
704 __isl_keep isl_mat
*div
, int pos
, __isl_take isl_printer
*p
)
706 p
= isl_printer_print_str(p
, "[(");
707 p
= print_affine_of_len(dim
, p
, div
->row
[pos
] + 1, div
->n_col
- 1, 1);
708 p
= isl_printer_print_str(p
, ")/");
709 p
= isl_printer_print_isl_int(p
, div
->row
[pos
][0]);
710 p
= isl_printer_print_str(p
, "]");
714 static __isl_give isl_printer
*upoly_print_cst(__isl_keep
struct isl_upoly
*up
,
715 __isl_take isl_printer
*p
, int first
)
717 struct isl_upoly_cst
*cst
;
720 cst
= isl_upoly_as_cst(up
);
723 neg
= !first
&& isl_int_is_neg(cst
->n
);
725 p
= isl_printer_print_str(p
, neg
? " - " : " + ");
727 isl_int_neg(cst
->n
, cst
->n
);
728 if (isl_int_is_zero(cst
->d
)) {
729 int sgn
= isl_int_sgn(cst
->n
);
730 p
= isl_printer_print_str(p
, sgn
< 0 ? "-infty" :
731 sgn
== 0 ? "NaN" : "infty");
733 p
= isl_printer_print_isl_int(p
, cst
->n
);
735 isl_int_neg(cst
->n
, cst
->n
);
736 if (!isl_int_is_zero(cst
->d
) && !isl_int_is_one(cst
->d
)) {
737 p
= isl_printer_print_str(p
, "/");
738 p
= isl_printer_print_isl_int(p
, cst
->d
);
746 static __isl_give isl_printer
*upoly_print(__isl_keep
struct isl_upoly
*up
,
747 __isl_keep isl_dim
*dim
, __isl_keep isl_mat
*div
,
748 __isl_take isl_printer
*p
)
752 struct isl_upoly_rec
*rec
;
754 if (!p
|| !up
|| !dim
|| !div
)
757 if (isl_upoly_is_cst(up
))
758 return upoly_print_cst(up
, p
, 1);
760 total
= isl_dim_total(dim
);
761 rec
= isl_upoly_as_rec(up
);
764 n
= upoly_rec_n_non_zero(rec
);
766 p
= isl_printer_print_str(p
, "(");
767 for (i
= 0, first
= 1; i
< rec
->n
; ++i
) {
768 if (isl_upoly_is_zero(rec
->p
[i
]))
770 if (isl_upoly_is_negone(rec
->p
[i
])) {
772 p
= isl_printer_print_str(p
, "-1");
774 p
= isl_printer_print_str(p
, "-");
776 p
= isl_printer_print_str(p
, " - ");
777 } else if (isl_upoly_is_cst(rec
->p
[i
]) &&
778 !isl_upoly_is_one(rec
->p
[i
]))
779 p
= upoly_print_cst(rec
->p
[i
], p
, first
);
782 p
= isl_printer_print_str(p
, " + ");
783 if (i
== 0 || !isl_upoly_is_one(rec
->p
[i
]))
784 p
= upoly_print(rec
->p
[i
], dim
, div
, p
);
789 if (!isl_upoly_is_one(rec
->p
[i
]) &&
790 !isl_upoly_is_negone(rec
->p
[i
]))
791 p
= isl_printer_print_str(p
, " * ");
792 if (rec
->up
.var
< total
)
793 p
= print_term(dim
, up
->ctx
->one
, 1 + rec
->up
.var
, p
, 1);
795 p
= print_div(dim
, div
, rec
->up
.var
- total
, p
);
798 p
= isl_printer_print_str(p
, "^");
799 p
= isl_printer_print_int(p
, i
);
802 p
= isl_printer_print_str(p
, ")");
809 __isl_give isl_printer
*isl_printer_print_qpolynomial(__isl_take isl_printer
*p
,
810 __isl_keep isl_qpolynomial
*qp
)
814 p
= upoly_print(qp
->upoly
, qp
->dim
, qp
->div
, p
);
821 void isl_qpolynomial_print(__isl_keep isl_qpolynomial
*qp
, FILE *out
,
822 unsigned output_format
)
829 isl_assert(qp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
830 p
= isl_printer_to_file(qp
->dim
->ctx
, out
);
831 p
= isl_printer_print_qpolynomial(p
, qp
);
835 static __isl_give isl_printer
*qpolynomial_fold_print(
836 __isl_keep isl_qpolynomial_fold
*fold
, __isl_take isl_printer
*p
)
840 if (fold
->type
== isl_fold_min
)
841 p
= isl_printer_print_str(p
, "min");
842 else if (fold
->type
== isl_fold_max
)
843 p
= isl_printer_print_str(p
, "max");
844 p
= isl_printer_print_str(p
, "(");
845 for (i
= 0; i
< fold
->n
; ++i
) {
847 p
= isl_printer_print_str(p
, ", ");
848 p
= isl_printer_print_qpolynomial(p
, fold
->qp
[i
]);
850 p
= isl_printer_print_str(p
, ")");
854 __isl_give isl_printer
*isl_printer_print_qpolynomial_fold(
855 __isl_take isl_printer
*p
, __isl_keep isl_qpolynomial_fold
*fold
)
859 p
= qpolynomial_fold_print(fold
, p
);
866 void isl_qpolynomial_fold_print(__isl_keep isl_qpolynomial_fold
*fold
,
867 FILE *out
, unsigned output_format
)
874 isl_assert(fold
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
876 p
= isl_printer_to_file(fold
->dim
->ctx
, out
);
877 p
= isl_printer_print_qpolynomial_fold(p
, fold
);
882 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial(
883 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial
*pwqp
)
890 if (isl_dim_size(pwqp
->dim
, isl_dim_param
) > 0) {
891 p
= print_tuple(pwqp
->dim
, p
, isl_dim_param
, 0);
892 p
= isl_printer_print_str(p
, " -> ");
894 p
= isl_printer_print_str(p
, "{ ");
896 if (isl_dim_size(pwqp
->dim
, isl_dim_set
) > 0) {
897 p
= print_tuple(pwqp
->dim
, p
, isl_dim_set
, 1);
898 p
= isl_printer_print_str(p
, " -> ");
900 p
= isl_printer_print_str(p
, "0");
902 for (i
= 0; i
< pwqp
->n
; ++i
) {
904 p
= isl_printer_print_str(p
, "; ");
905 if (isl_dim_size(pwqp
->p
[i
].set
->dim
, isl_dim_set
) > 0) {
906 p
= print_tuple(pwqp
->p
[i
].set
->dim
, p
, isl_dim_set
, 1);
907 p
= isl_printer_print_str(p
, " -> ");
909 p
= isl_printer_print_qpolynomial(p
, pwqp
->p
[i
].qp
);
910 p
= print_disjuncts((isl_map
*)pwqp
->p
[i
].set
, p
, 1);
912 p
= isl_printer_print_str(p
, " }");
919 void isl_pw_qpolynomial_print(__isl_keep isl_pw_qpolynomial
*pwqp
, FILE *out
,
920 unsigned output_format
)
927 isl_assert(pwqp
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
929 p
= isl_printer_to_file(pwqp
->dim
->ctx
, out
);
930 p
= isl_printer_print_pw_qpolynomial(p
, pwqp
);
935 __isl_give isl_printer
*isl_printer_print_pw_qpolynomial_fold(
936 __isl_take isl_printer
*p
, __isl_keep isl_pw_qpolynomial_fold
*pwf
)
943 if (isl_dim_size(pwf
->dim
, isl_dim_param
) > 0) {
944 p
= print_tuple(pwf
->dim
, p
, isl_dim_param
, 0);
945 p
= isl_printer_print_str(p
, " -> ");
947 p
= isl_printer_print_str(p
, "{ ");
949 if (isl_dim_size(pwf
->dim
, isl_dim_set
) > 0) {
950 p
= print_tuple(pwf
->dim
, p
, isl_dim_set
, 0);
951 p
= isl_printer_print_str(p
, " -> ");
953 p
= isl_printer_print_str(p
, "0");
955 for (i
= 0; i
< pwf
->n
; ++i
) {
957 p
= isl_printer_print_str(p
, "; ");
958 if (isl_dim_size(pwf
->p
[i
].set
->dim
, isl_dim_set
) > 0) {
959 p
= print_tuple(pwf
->p
[i
].set
->dim
, p
, isl_dim_set
, 0);
960 p
= isl_printer_print_str(p
, " -> ");
962 p
= qpolynomial_fold_print(pwf
->p
[i
].fold
, p
);
963 p
= print_disjuncts((isl_map
*)pwf
->p
[i
].set
, p
, 1);
965 p
= isl_printer_print_str(p
, " }");
969 void isl_pw_qpolynomial_fold_print(__isl_keep isl_pw_qpolynomial_fold
*pwf
,
970 FILE *out
, unsigned output_format
)
977 isl_assert(pwf
->dim
->ctx
, output_format
== ISL_FORMAT_ISL
, return);
979 p
= isl_printer_to_file(pwf
->dim
->ctx
, out
);
980 p
= isl_printer_print_pw_qpolynomial_fold(p
, pwf
);