1 #include "isl_map_private.h"
5 * The implementation of tableaus in this file was inspired by Section 8
6 * of David Detlefs, Greg Nelson and James B. Saxe, "Simplify: a theorem
7 * prover for program checking".
10 struct isl_tab *isl_tab_alloc(struct isl_ctx *ctx,
11 unsigned n_row, unsigned n_var)
16 tab = isl_calloc_type(ctx, struct isl_tab);
19 tab->mat = isl_mat_alloc(ctx, n_row, 2 + n_var);
22 tab->var = isl_alloc_array(ctx, struct isl_tab_var, n_var);
25 tab->con = isl_alloc_array(ctx, struct isl_tab_var, n_row);
28 tab->col_var = isl_alloc_array(ctx, int, n_var);
31 tab->row_var = isl_alloc_array(ctx, int, n_row);
34 for (i = 0; i < n_var; ++i) {
35 tab->var[i].index = i;
36 tab->var[i].is_row = 0;
37 tab->var[i].is_nonneg = 0;
38 tab->var[i].is_zero = 0;
39 tab->var[i].is_redundant = 0;
40 tab->var[i].frozen = 0;
55 tab->bottom.type = isl_tab_undo_bottom;
56 tab->bottom.next = NULL;
57 tab->top = &tab->bottom;
64 static int extend_cons(struct isl_tab *tab, unsigned n_new)
66 if (tab->max_con < tab->n_con + n_new) {
67 struct isl_tab_var *con;
69 con = isl_realloc_array(tab->mat->ctx, tab->con,
70 struct isl_tab_var, tab->max_con + n_new);
74 tab->max_con += n_new;
76 if (tab->mat->n_row < tab->n_row + n_new) {
79 tab->mat = isl_mat_extend(tab->mat,
80 tab->n_row + n_new, tab->n_col);
83 row_var = isl_realloc_array(tab->mat->ctx, tab->row_var,
84 int, tab->mat->n_row);
87 tab->row_var = row_var;
92 struct isl_tab *isl_tab_extend(struct isl_tab *tab, unsigned n_new)
94 if (extend_cons(tab, n_new) >= 0)
101 static void free_undo(struct isl_tab *tab)
103 struct isl_tab_undo *undo, *next;
105 for (undo = tab->top; undo && undo != &tab->bottom; undo = next) {
112 void isl_tab_free(struct isl_tab *tab)
117 isl_mat_free(tab->mat);
118 isl_vec_free(tab->dual);
126 static struct isl_tab_var *var_from_index(struct isl_tab *tab, int i)
131 return &tab->con[~i];
134 static struct isl_tab_var *var_from_row(struct isl_tab *tab, int i)
136 return var_from_index(tab, tab->row_var[i]);
139 static struct isl_tab_var *var_from_col(struct isl_tab *tab, int i)
141 return var_from_index(tab, tab->col_var[i]);
144 /* Check if there are any upper bounds on column variable "var",
145 * i.e., non-negative rows where var appears with a negative coefficient.
146 * Return 1 if there are no such bounds.
148 static int max_is_manifestly_unbounded(struct isl_tab *tab,
149 struct isl_tab_var *var)
155 for (i = tab->n_redundant; i < tab->n_row; ++i) {
156 if (!isl_int_is_neg(tab->mat->row[i][2 + var->index]))
158 if (var_from_row(tab, i)->is_nonneg)
164 /* Check if there are any lower bounds on column variable "var",
165 * i.e., non-negative rows where var appears with a positive coefficient.
166 * Return 1 if there are no such bounds.
168 static int min_is_manifestly_unbounded(struct isl_tab *tab,
169 struct isl_tab_var *var)
175 for (i = tab->n_redundant; i < tab->n_row; ++i) {
176 if (!isl_int_is_pos(tab->mat->row[i][2 + var->index]))
178 if (var_from_row(tab, i)->is_nonneg)
184 /* Given the index of a column "c", return the index of a row
185 * that can be used to pivot the column in, with either an increase
186 * (sgn > 0) or a decrease (sgn < 0) of the corresponding variable.
187 * If "var" is not NULL, then the row returned will be different from
188 * the one associated with "var".
190 * Each row in the tableau is of the form
192 * x_r = a_r0 + \sum_i a_ri x_i
194 * Only rows with x_r >= 0 and with the sign of a_ri opposite to "sgn"
195 * impose any limit on the increase or decrease in the value of x_c
196 * and this bound is equal to a_r0 / |a_rc|. We are therefore looking
197 * for the row with the smallest (most stringent) such bound.
198 * Note that the common denominator of each row drops out of the fraction.
199 * To check if row j has a smaller bound than row r, i.e.,
200 * a_j0 / |a_jc| < a_r0 / |a_rc| or a_j0 |a_rc| < a_r0 |a_jc|,
201 * we check if -sign(a_jc) (a_j0 a_rc - a_r0 a_jc) < 0,
202 * where -sign(a_jc) is equal to "sgn".
204 static int pivot_row(struct isl_tab *tab,
205 struct isl_tab_var *var, int sgn, int c)
212 for (j = tab->n_redundant; j < tab->n_row; ++j) {
213 if (var && j == var->index)
215 if (!var_from_row(tab, j)->is_nonneg)
217 if (sgn * isl_int_sgn(tab->mat->row[j][2 + c]) >= 0)
223 isl_int_mul(t, tab->mat->row[r][1], tab->mat->row[j][2 + c]);
224 isl_int_submul(t, tab->mat->row[j][1], tab->mat->row[r][2 + c]);
225 tsgn = sgn * isl_int_sgn(t);
226 if (tsgn < 0 || (tsgn == 0 &&
227 tab->row_var[j] < tab->row_var[r]))
234 /* Find a pivot (row and col) that will increase (sgn > 0) or decrease
235 * (sgn < 0) the value of row variable var.
236 * If not NULL, then skip_var is a row variable that should be ignored
237 * while looking for a pivot row. It is usually equal to var.
239 * As the given row in the tableau is of the form
241 * x_r = a_r0 + \sum_i a_ri x_i
243 * we need to find a column such that the sign of a_ri is equal to "sgn"
244 * (such that an increase in x_i will have the desired effect) or a
245 * column with a variable that may attain negative values.
246 * If a_ri is positive, then we need to move x_i in the same direction
247 * to obtain the desired effect. Otherwise, x_i has to move in the
248 * opposite direction.
250 static void find_pivot(struct isl_tab *tab,
251 struct isl_tab_var *var, struct isl_tab_var *skip_var,
252 int sgn, int *row, int *col)
259 isl_assert(tab->mat->ctx, var->is_row, return);
260 tr = tab->mat->row[var->index];
263 for (j = tab->n_dead; j < tab->n_col; ++j) {
264 if (isl_int_is_zero(tr[2 + j]))
266 if (isl_int_sgn(tr[2 + j]) != sgn &&
267 var_from_col(tab, j)->is_nonneg)
269 if (c < 0 || tab->col_var[j] < tab->col_var[c])
275 sgn *= isl_int_sgn(tr[2 + c]);
276 r = pivot_row(tab, skip_var, sgn, c);
277 *row = r < 0 ? var->index : r;
281 /* Return 1 if row "row" represents an obviously redundant inequality.
283 * - it represents an inequality or a variable
284 * - that is the sum of a non-negative sample value and a positive
285 * combination of zero or more non-negative variables.
287 static int is_redundant(struct isl_tab *tab, int row)
291 if (tab->row_var[row] < 0 && !var_from_row(tab, row)->is_nonneg)
294 if (isl_int_is_neg(tab->mat->row[row][1]))
297 for (i = tab->n_dead; i < tab->n_col; ++i) {
298 if (isl_int_is_zero(tab->mat->row[row][2 + i]))
300 if (isl_int_is_neg(tab->mat->row[row][2 + i]))
302 if (!var_from_col(tab, i)->is_nonneg)
308 static void swap_rows(struct isl_tab *tab, int row1, int row2)
311 t = tab->row_var[row1];
312 tab->row_var[row1] = tab->row_var[row2];
313 tab->row_var[row2] = t;
314 var_from_row(tab, row1)->index = row1;
315 var_from_row(tab, row2)->index = row2;
316 tab->mat = isl_mat_swap_rows(tab->mat, row1, row2);
319 static void push(struct isl_tab *tab,
320 enum isl_tab_undo_type type, struct isl_tab_var *var)
322 struct isl_tab_undo *undo;
327 undo = isl_alloc_type(tab->mat->ctx, struct isl_tab_undo);
335 undo->next = tab->top;
339 /* Mark row with index "row" as being redundant.
340 * If we may need to undo the operation or if the row represents
341 * a variable of the original problem, the row is kept,
342 * but no longer considered when looking for a pivot row.
343 * Otherwise, the row is simply removed.
345 * The row may be interchanged with some other row. If it
346 * is interchanged with a later row, return 1. Otherwise return 0.
347 * If the rows are checked in order in the calling function,
348 * then a return value of 1 means that the row with the given
349 * row number may now contain a different row that hasn't been checked yet.
351 static int mark_redundant(struct isl_tab *tab, int row)
353 struct isl_tab_var *var = var_from_row(tab, row);
354 var->is_redundant = 1;
355 isl_assert(tab->mat->ctx, row >= tab->n_redundant, return);
356 if (tab->need_undo || tab->row_var[row] >= 0) {
357 if (tab->row_var[row] >= 0) {
359 push(tab, isl_tab_undo_nonneg, var);
361 if (row != tab->n_redundant)
362 swap_rows(tab, row, tab->n_redundant);
363 push(tab, isl_tab_undo_redundant, var);
367 if (row != tab->n_row - 1)
368 swap_rows(tab, row, tab->n_row - 1);
369 var_from_row(tab, tab->n_row - 1)->index = -1;
375 static struct isl_tab *mark_empty(struct isl_tab *tab)
377 if (!tab->empty && tab->need_undo)
378 push(tab, isl_tab_undo_empty, NULL);
383 /* Given a row number "row" and a column number "col", pivot the tableau
384 * such that the associated variables are interchanged.
385 * The given row in the tableau expresses
387 * x_r = a_r0 + \sum_i a_ri x_i
391 * x_c = 1/a_rc x_r - a_r0/a_rc + sum_{i \ne r} -a_ri/a_rc
393 * Substituting this equality into the other rows
395 * x_j = a_j0 + \sum_i a_ji x_i
397 * with a_jc \ne 0, we obtain
399 * x_j = a_jc/a_rc x_r + a_j0 - a_jc a_r0/a_rc + sum a_ji - a_jc a_ri/a_rc
406 * where i is any other column and j is any other row,
407 * is therefore transformed into
409 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
410 * s(n_rc)d_r n_jc/(|n_rc| d_j) (n_ji |n_rc| - s(n_rc)n_jc n_ri)/(|n_rc| d_j)
412 * The transformation is performed along the following steps
417 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
420 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
421 * n_jc/(|n_rc| d_j) n_ji/(|n_rc| d_j)
423 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
424 * n_jc/(|n_rc| d_j) (n_ji |n_rc|)/(|n_rc| d_j)
426 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
427 * n_jc/(|n_rc| d_j) (n_ji |n_rc| - s(n_rc)n_jc n_ri)/(|n_rc| d_j)
429 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
430 * s(n_rc)d_r n_jc/(|n_rc| d_j) (n_ji |n_rc| - s(n_rc)n_jc n_ri)/(|n_rc| d_j)
433 static void pivot(struct isl_tab *tab, int row, int col)
438 struct isl_mat *mat = tab->mat;
439 struct isl_tab_var *var;
441 isl_int_swap(mat->row[row][0], mat->row[row][2 + col]);
442 sgn = isl_int_sgn(mat->row[row][0]);
444 isl_int_neg(mat->row[row][0], mat->row[row][0]);
445 isl_int_neg(mat->row[row][2 + col], mat->row[row][2 + col]);
447 for (j = 0; j < 1 + tab->n_col; ++j) {
450 isl_int_neg(mat->row[row][1 + j], mat->row[row][1 + j]);
452 if (!isl_int_is_one(mat->row[row][0]))
453 isl_seq_normalize(mat->row[row], 2 + tab->n_col);
454 for (i = 0; i < tab->n_row; ++i) {
457 if (isl_int_is_zero(mat->row[i][2 + col]))
459 isl_int_mul(mat->row[i][0], mat->row[i][0], mat->row[row][0]);
460 for (j = 0; j < 1 + tab->n_col; ++j) {
463 isl_int_mul(mat->row[i][1 + j],
464 mat->row[i][1 + j], mat->row[row][0]);
465 isl_int_addmul(mat->row[i][1 + j],
466 mat->row[i][2 + col], mat->row[row][1 + j]);
468 isl_int_mul(mat->row[i][2 + col],
469 mat->row[i][2 + col], mat->row[row][2 + col]);
470 if (!isl_int_is_one(mat->row[row][0]))
471 isl_seq_normalize(mat->row[i], 2 + tab->n_col);
473 t = tab->row_var[row];
474 tab->row_var[row] = tab->col_var[col];
475 tab->col_var[col] = t;
476 var = var_from_row(tab, row);
479 var = var_from_col(tab, col);
484 for (i = tab->n_redundant; i < tab->n_row; ++i) {
485 if (isl_int_is_zero(mat->row[i][2 + col]))
487 if (!var_from_row(tab, i)->frozen &&
488 is_redundant(tab, i))
489 if (mark_redundant(tab, i))
494 /* If "var" represents a column variable, then pivot is up (sgn > 0)
495 * or down (sgn < 0) to a row. The variable is assumed not to be
496 * unbounded in the specified direction.
498 static void to_row(struct isl_tab *tab, struct isl_tab_var *var, int sign)
505 r = pivot_row(tab, NULL, sign, var->index);
506 isl_assert(tab->mat->ctx, r >= 0, return);
507 pivot(tab, r, var->index);
510 static void check_table(struct isl_tab *tab)
516 for (i = 0; i < tab->n_row; ++i) {
517 if (!var_from_row(tab, i)->is_nonneg)
519 assert(!isl_int_is_neg(tab->mat->row[i][1]));
523 /* Return the sign of the maximal value of "var".
524 * If the sign is not negative, then on return from this function,
525 * the sample value will also be non-negative.
527 * If "var" is manifestly unbounded wrt positive values, we are done.
528 * Otherwise, we pivot the variable up to a row if needed
529 * Then we continue pivoting down until either
530 * - no more down pivots can be performed
531 * - the sample value is positive
532 * - the variable is pivoted into a manifestly unbounded column
534 static int sign_of_max(struct isl_tab *tab, struct isl_tab_var *var)
538 if (max_is_manifestly_unbounded(tab, var))
541 while (!isl_int_is_pos(tab->mat->row[var->index][1])) {
542 find_pivot(tab, var, var, 1, &row, &col);
544 return isl_int_sgn(tab->mat->row[var->index][1]);
545 pivot(tab, row, col);
546 if (!var->is_row) /* manifestly unbounded */
552 /* Perform pivots until the row variable "var" has a non-negative
553 * sample value or until no more upward pivots can be performed.
554 * Return the sign of the sample value after the pivots have been
557 static int restore_row(struct isl_tab *tab, struct isl_tab_var *var)
561 while (isl_int_is_neg(tab->mat->row[var->index][1])) {
562 find_pivot(tab, var, var, 1, &row, &col);
565 pivot(tab, row, col);
566 if (!var->is_row) /* manifestly unbounded */
569 return isl_int_sgn(tab->mat->row[var->index][1]);
572 /* Perform pivots until we are sure that the row variable "var"
573 * can attain non-negative values. After return from this
574 * function, "var" is still a row variable, but its sample
575 * value may not be non-negative, even if the function returns 1.
577 static int at_least_zero(struct isl_tab *tab, struct isl_tab_var *var)
581 while (isl_int_is_neg(tab->mat->row[var->index][1])) {
582 find_pivot(tab, var, var, 1, &row, &col);
585 if (row == var->index) /* manifestly unbounded */
587 pivot(tab, row, col);
589 return !isl_int_is_neg(tab->mat->row[var->index][1]);
592 /* Return a negative value if "var" can attain negative values.
593 * Return a non-negative value otherwise.
595 * If "var" is manifestly unbounded wrt negative values, we are done.
596 * Otherwise, if var is in a column, we can pivot it down to a row.
597 * Then we continue pivoting down until either
598 * - the pivot would result in a manifestly unbounded column
599 * => we don't perform the pivot, but simply return -1
600 * - no more down pivots can be performed
601 * - the sample value is negative
602 * If the sample value becomes negative and the variable is supposed
603 * to be nonnegative, then we undo the last pivot.
604 * However, if the last pivot has made the pivoting variable
605 * obviously redundant, then it may have moved to another row.
606 * In that case we look for upward pivots until we reach a non-negative
609 static int sign_of_min(struct isl_tab *tab, struct isl_tab_var *var)
612 struct isl_tab_var *pivot_var;
614 if (min_is_manifestly_unbounded(tab, var))
618 row = pivot_row(tab, NULL, -1, col);
619 pivot_var = var_from_col(tab, col);
620 pivot(tab, row, col);
621 if (var->is_redundant)
623 if (isl_int_is_neg(tab->mat->row[var->index][1])) {
624 if (var->is_nonneg) {
625 if (!pivot_var->is_redundant &&
626 pivot_var->index == row)
627 pivot(tab, row, col);
629 restore_row(tab, var);
634 if (var->is_redundant)
636 while (!isl_int_is_neg(tab->mat->row[var->index][1])) {
637 find_pivot(tab, var, var, -1, &row, &col);
638 if (row == var->index)
641 return isl_int_sgn(tab->mat->row[var->index][1]);
642 pivot_var = var_from_col(tab, col);
643 pivot(tab, row, col);
644 if (var->is_redundant)
647 if (var->is_nonneg) {
648 /* pivot back to non-negative value */
649 if (!pivot_var->is_redundant && pivot_var->index == row)
650 pivot(tab, row, col);
652 restore_row(tab, var);
657 /* Return 1 if "var" can attain values <= -1.
658 * Return 0 otherwise.
660 * The sample value of "var" is assumed to be non-negative when the
661 * the function is called and will be made non-negative again before
662 * the function returns.
664 static int min_at_most_neg_one(struct isl_tab *tab, struct isl_tab_var *var)
667 struct isl_tab_var *pivot_var;
669 if (min_is_manifestly_unbounded(tab, var))
673 row = pivot_row(tab, NULL, -1, col);
674 pivot_var = var_from_col(tab, col);
675 pivot(tab, row, col);
676 if (var->is_redundant)
678 if (isl_int_is_neg(tab->mat->row[var->index][1]) &&
679 isl_int_abs_ge(tab->mat->row[var->index][1],
680 tab->mat->row[var->index][0])) {
681 if (var->is_nonneg) {
682 if (!pivot_var->is_redundant &&
683 pivot_var->index == row)
684 pivot(tab, row, col);
686 restore_row(tab, var);
691 if (var->is_redundant)
694 find_pivot(tab, var, var, -1, &row, &col);
695 if (row == var->index)
699 pivot_var = var_from_col(tab, col);
700 pivot(tab, row, col);
701 if (var->is_redundant)
703 } while (!isl_int_is_neg(tab->mat->row[var->index][1]) ||
704 isl_int_abs_lt(tab->mat->row[var->index][1],
705 tab->mat->row[var->index][0]));
706 if (var->is_nonneg) {
707 /* pivot back to non-negative value */
708 if (!pivot_var->is_redundant && pivot_var->index == row)
709 pivot(tab, row, col);
710 restore_row(tab, var);
715 /* Return 1 if "var" can attain values >= 1.
716 * Return 0 otherwise.
718 static int at_least_one(struct isl_tab *tab, struct isl_tab_var *var)
723 if (max_is_manifestly_unbounded(tab, var))
726 r = tab->mat->row[var->index];
727 while (isl_int_lt(r[1], r[0])) {
728 find_pivot(tab, var, var, 1, &row, &col);
730 return isl_int_ge(r[1], r[0]);
731 if (row == var->index) /* manifestly unbounded */
733 pivot(tab, row, col);
738 static void swap_cols(struct isl_tab *tab, int col1, int col2)
741 t = tab->col_var[col1];
742 tab->col_var[col1] = tab->col_var[col2];
743 tab->col_var[col2] = t;
744 var_from_col(tab, col1)->index = col1;
745 var_from_col(tab, col2)->index = col2;
746 tab->mat = isl_mat_swap_cols(tab->mat, 2 + col1, 2 + col2);
749 /* Mark column with index "col" as representing a zero variable.
750 * If we may need to undo the operation the column is kept,
751 * but no longer considered.
752 * Otherwise, the column is simply removed.
754 * The column may be interchanged with some other column. If it
755 * is interchanged with a later column, return 1. Otherwise return 0.
756 * If the columns are checked in order in the calling function,
757 * then a return value of 1 means that the column with the given
758 * column number may now contain a different column that
759 * hasn't been checked yet.
761 static int kill_col(struct isl_tab *tab, int col)
763 var_from_col(tab, col)->is_zero = 1;
764 if (tab->need_undo) {
765 push(tab, isl_tab_undo_zero, var_from_col(tab, col));
766 if (col != tab->n_dead)
767 swap_cols(tab, col, tab->n_dead);
771 if (col != tab->n_col - 1)
772 swap_cols(tab, col, tab->n_col - 1);
773 var_from_col(tab, tab->n_col - 1)->index = -1;
779 /* Row variable "var" is non-negative and cannot attain any values
780 * larger than zero. This means that the coefficients of the unrestricted
781 * column variables are zero and that the coefficients of the non-negative
782 * column variables are zero or negative.
783 * Each of the non-negative variables with a negative coefficient can
784 * then also be written as the negative sum of non-negative variables
785 * and must therefore also be zero.
787 static void close_row(struct isl_tab *tab, struct isl_tab_var *var)
790 struct isl_mat *mat = tab->mat;
792 isl_assert(tab->mat->ctx, var->is_nonneg, return);
794 for (j = tab->n_dead; j < tab->n_col; ++j) {
795 if (isl_int_is_zero(mat->row[var->index][2 + j]))
797 isl_assert(tab->mat->ctx,
798 isl_int_is_neg(mat->row[var->index][2 + j]), return);
799 if (kill_col(tab, j))
802 mark_redundant(tab, var->index);
805 /* Add a constraint to the tableau and allocate a row for it.
806 * Return the index into the constraint array "con".
808 static int allocate_con(struct isl_tab *tab)
812 isl_assert(tab->mat->ctx, tab->n_row < tab->mat->n_row, return -1);
815 tab->con[r].index = tab->n_row;
816 tab->con[r].is_row = 1;
817 tab->con[r].is_nonneg = 0;
818 tab->con[r].is_zero = 0;
819 tab->con[r].is_redundant = 0;
820 tab->con[r].frozen = 0;
821 tab->row_var[tab->n_row] = ~r;
825 push(tab, isl_tab_undo_allocate, &tab->con[r]);
830 /* Add a row to the tableau. The row is given as an affine combination
831 * of the original variables and needs to be expressed in terms of the
834 * We add each term in turn.
835 * If r = n/d_r is the current sum and we need to add k x, then
836 * if x is a column variable, we increase the numerator of
837 * this column by k d_r
838 * if x = f/d_x is a row variable, then the new representation of r is
840 * n k f d_x/g n + d_r/g k f m/d_r n + m/d_g k f
841 * --- + --- = ------------------- = -------------------
842 * d_r d_r d_r d_x/g m
844 * with g the gcd of d_r and d_x and m the lcm of d_r and d_x.
846 static int add_row(struct isl_tab *tab, isl_int *line)
853 r = allocate_con(tab);
859 row = tab->mat->row[tab->con[r].index];
860 isl_int_set_si(row[0], 1);
861 isl_int_set(row[1], line[0]);
862 isl_seq_clr(row + 2, tab->n_col);
863 for (i = 0; i < tab->n_var; ++i) {
864 if (tab->var[i].is_zero)
866 if (tab->var[i].is_row) {
868 row[0], tab->mat->row[tab->var[i].index][0]);
869 isl_int_swap(a, row[0]);
870 isl_int_divexact(a, row[0], a);
872 row[0], tab->mat->row[tab->var[i].index][0]);
873 isl_int_mul(b, b, line[1 + i]);
874 isl_seq_combine(row + 1, a, row + 1,
875 b, tab->mat->row[tab->var[i].index] + 1,
878 isl_int_addmul(row[2 + tab->var[i].index],
879 line[1 + i], row[0]);
881 isl_seq_normalize(row, 2 + tab->n_col);
888 static int drop_row(struct isl_tab *tab, int row)
890 isl_assert(tab->mat->ctx, ~tab->row_var[row] == tab->n_con - 1, return -1);
891 if (row != tab->n_row - 1)
892 swap_rows(tab, row, tab->n_row - 1);
898 /* Add inequality "ineq" and check if it conflicts with the
899 * previously added constraints or if it is obviously redundant.
901 struct isl_tab *isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq)
908 r = add_row(tab, ineq);
911 tab->con[r].is_nonneg = 1;
912 push(tab, isl_tab_undo_nonneg, &tab->con[r]);
913 if (is_redundant(tab, tab->con[r].index)) {
914 mark_redundant(tab, tab->con[r].index);
918 sgn = restore_row(tab, &tab->con[r]);
920 return mark_empty(tab);
921 if (tab->con[r].is_row && is_redundant(tab, tab->con[r].index))
922 mark_redundant(tab, tab->con[r].index);
929 /* Pivot a non-negative variable down until it reaches the value zero
930 * and then pivot the variable into a column position.
932 static int to_col(struct isl_tab *tab, struct isl_tab_var *var)
940 while (isl_int_is_pos(tab->mat->row[var->index][1])) {
941 find_pivot(tab, var, NULL, -1, &row, &col);
942 isl_assert(tab->mat->ctx, row != -1, return -1);
943 pivot(tab, row, col);
948 for (i = tab->n_dead; i < tab->n_col; ++i)
949 if (!isl_int_is_zero(tab->mat->row[var->index][2 + i]))
952 isl_assert(tab->mat->ctx, i < tab->n_col, return -1);
953 pivot(tab, var->index, i);
958 /* We assume Gaussian elimination has been performed on the equalities.
959 * The equalities can therefore never conflict.
960 * Adding the equalities is currently only really useful for a later call
961 * to isl_tab_ineq_type.
963 static struct isl_tab *add_eq(struct isl_tab *tab, isl_int *eq)
970 r = add_row(tab, eq);
974 r = tab->con[r].index;
975 i = isl_seq_first_non_zero(tab->mat->row[r] + 2 + tab->n_dead,
976 tab->n_col - tab->n_dead);
977 isl_assert(tab->mat->ctx, i >= 0, goto error);
989 /* Add an equality that is known to be valid for the given tableau.
991 struct isl_tab *isl_tab_add_valid_eq(struct isl_tab *tab, isl_int *eq)
993 struct isl_tab_var *var;
999 r = add_row(tab, eq);
1005 if (isl_int_is_neg(tab->mat->row[r][1]))
1006 isl_seq_neg(tab->mat->row[r] + 1, tab->mat->row[r] + 1,
1009 if (to_col(tab, var) < 0)
1012 kill_col(tab, var->index);
1020 struct isl_tab *isl_tab_from_basic_map(struct isl_basic_map *bmap)
1023 struct isl_tab *tab;
1027 tab = isl_tab_alloc(bmap->ctx,
1028 isl_basic_map_total_dim(bmap) + bmap->n_ineq + 1,
1029 isl_basic_map_total_dim(bmap));
1032 tab->rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
1033 if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_EMPTY))
1034 return mark_empty(tab);
1035 for (i = 0; i < bmap->n_eq; ++i) {
1036 tab = add_eq(tab, bmap->eq[i]);
1040 for (i = 0; i < bmap->n_ineq; ++i) {
1041 tab = isl_tab_add_ineq(tab, bmap->ineq[i]);
1042 if (!tab || tab->empty)
1048 struct isl_tab *isl_tab_from_basic_set(struct isl_basic_set *bset)
1050 return isl_tab_from_basic_map((struct isl_basic_map *)bset);
1053 /* Construct a tableau corresponding to the recession cone of "bmap".
1055 struct isl_tab *isl_tab_from_recession_cone(struct isl_basic_map *bmap)
1059 struct isl_tab *tab;
1063 tab = isl_tab_alloc(bmap->ctx, bmap->n_eq + bmap->n_ineq,
1064 isl_basic_map_total_dim(bmap));
1067 tab->rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL);
1070 for (i = 0; i < bmap->n_eq; ++i) {
1071 isl_int_swap(bmap->eq[i][0], cst);
1072 tab = add_eq(tab, bmap->eq[i]);
1073 isl_int_swap(bmap->eq[i][0], cst);
1077 for (i = 0; i < bmap->n_ineq; ++i) {
1079 isl_int_swap(bmap->ineq[i][0], cst);
1080 r = add_row(tab, bmap->ineq[i]);
1081 isl_int_swap(bmap->ineq[i][0], cst);
1084 tab->con[r].is_nonneg = 1;
1085 push(tab, isl_tab_undo_nonneg, &tab->con[r]);
1096 /* Assuming "tab" is the tableau of a cone, check if the cone is
1097 * bounded, i.e., if it is empty or only contains the origin.
1099 int isl_tab_cone_is_bounded(struct isl_tab *tab)
1107 if (tab->n_dead == tab->n_col)
1111 for (i = tab->n_redundant; i < tab->n_row; ++i) {
1112 struct isl_tab_var *var;
1113 var = var_from_row(tab, i);
1114 if (!var->is_nonneg)
1116 if (sign_of_max(tab, var) != 0)
1118 close_row(tab, var);
1121 if (tab->n_dead == tab->n_col)
1123 if (i == tab->n_row)
1128 int isl_tab_sample_is_integer(struct isl_tab *tab)
1135 for (i = 0; i < tab->n_var; ++i) {
1137 if (!tab->var[i].is_row)
1139 row = tab->var[i].index;
1140 if (!isl_int_is_divisible_by(tab->mat->row[row][1],
1141 tab->mat->row[row][0]))
1147 static struct isl_vec *extract_integer_sample(struct isl_tab *tab)
1150 struct isl_vec *vec;
1152 vec = isl_vec_alloc(tab->mat->ctx, 1 + tab->n_var);
1156 isl_int_set_si(vec->block.data[0], 1);
1157 for (i = 0; i < tab->n_var; ++i) {
1158 if (!tab->var[i].is_row)
1159 isl_int_set_si(vec->block.data[1 + i], 0);
1161 int row = tab->var[i].index;
1162 isl_int_divexact(vec->block.data[1 + i],
1163 tab->mat->row[row][1], tab->mat->row[row][0]);
1170 struct isl_vec *isl_tab_get_sample_value(struct isl_tab *tab)
1173 struct isl_vec *vec;
1179 vec = isl_vec_alloc(tab->mat->ctx, 1 + tab->n_var);
1185 isl_int_set_si(vec->block.data[0], 1);
1186 for (i = 0; i < tab->n_var; ++i) {
1188 if (!tab->var[i].is_row) {
1189 isl_int_set_si(vec->block.data[1 + i], 0);
1192 row = tab->var[i].index;
1193 isl_int_gcd(m, vec->block.data[0], tab->mat->row[row][0]);
1194 isl_int_divexact(m, tab->mat->row[row][0], m);
1195 isl_seq_scale(vec->block.data, vec->block.data, m, 1 + i);
1196 isl_int_divexact(m, vec->block.data[0], tab->mat->row[row][0]);
1197 isl_int_mul(vec->block.data[1 + i], m, tab->mat->row[row][1]);
1199 isl_seq_normalize(vec->block.data, vec->size);
1205 /* Update "bmap" based on the results of the tableau "tab".
1206 * In particular, implicit equalities are made explicit, redundant constraints
1207 * are removed and if the sample value happens to be integer, it is stored
1208 * in "bmap" (unless "bmap" already had an integer sample).
1210 * The tableau is assumed to have been created from "bmap" using
1211 * isl_tab_from_basic_map.
1213 struct isl_basic_map *isl_basic_map_update_from_tab(struct isl_basic_map *bmap,
1214 struct isl_tab *tab)
1226 bmap = isl_basic_map_set_to_empty(bmap);
1228 for (i = bmap->n_ineq - 1; i >= 0; --i) {
1229 if (isl_tab_is_equality(tab, n_eq + i))
1230 isl_basic_map_inequality_to_equality(bmap, i);
1231 else if (isl_tab_is_redundant(tab, n_eq + i))
1232 isl_basic_map_drop_inequality(bmap, i);
1234 if (!tab->rational &&
1235 !bmap->sample && isl_tab_sample_is_integer(tab))
1236 bmap->sample = extract_integer_sample(tab);
1240 struct isl_basic_set *isl_basic_set_update_from_tab(struct isl_basic_set *bset,
1241 struct isl_tab *tab)
1243 return (struct isl_basic_set *)isl_basic_map_update_from_tab(
1244 (struct isl_basic_map *)bset, tab);
1247 /* Given a non-negative variable "var", add a new non-negative variable
1248 * that is the opposite of "var", ensuring that var can only attain the
1250 * If var = n/d is a row variable, then the new variable = -n/d.
1251 * If var is a column variables, then the new variable = -var.
1252 * If the new variable cannot attain non-negative values, then
1253 * the resulting tableau is empty.
1254 * Otherwise, we know the value will be zero and we close the row.
1256 static struct isl_tab *cut_to_hyperplane(struct isl_tab *tab,
1257 struct isl_tab_var *var)
1263 if (extend_cons(tab, 1) < 0)
1267 tab->con[r].index = tab->n_row;
1268 tab->con[r].is_row = 1;
1269 tab->con[r].is_nonneg = 0;
1270 tab->con[r].is_zero = 0;
1271 tab->con[r].is_redundant = 0;
1272 tab->con[r].frozen = 0;
1273 tab->row_var[tab->n_row] = ~r;
1274 row = tab->mat->row[tab->n_row];
1277 isl_int_set(row[0], tab->mat->row[var->index][0]);
1278 isl_seq_neg(row + 1,
1279 tab->mat->row[var->index] + 1, 1 + tab->n_col);
1281 isl_int_set_si(row[0], 1);
1282 isl_seq_clr(row + 1, 1 + tab->n_col);
1283 isl_int_set_si(row[2 + var->index], -1);
1288 push(tab, isl_tab_undo_allocate, &tab->con[r]);
1290 sgn = sign_of_max(tab, &tab->con[r]);
1292 return mark_empty(tab);
1293 tab->con[r].is_nonneg = 1;
1294 push(tab, isl_tab_undo_nonneg, &tab->con[r]);
1296 close_row(tab, &tab->con[r]);
1304 /* Given a tableau "tab" and an inequality constraint "con" of the tableau,
1305 * relax the inequality by one. That is, the inequality r >= 0 is replaced
1306 * by r' = r + 1 >= 0.
1307 * If r is a row variable, we simply increase the constant term by one
1308 * (taking into account the denominator).
1309 * If r is a column variable, then we need to modify each row that
1310 * refers to r = r' - 1 by substituting this equality, effectively
1311 * subtracting the coefficient of the column from the constant.
1313 struct isl_tab *isl_tab_relax(struct isl_tab *tab, int con)
1315 struct isl_tab_var *var;
1319 var = &tab->con[con];
1321 if (!var->is_row && !max_is_manifestly_unbounded(tab, var))
1322 to_row(tab, var, 1);
1325 isl_int_add(tab->mat->row[var->index][1],
1326 tab->mat->row[var->index][1], tab->mat->row[var->index][0]);
1330 for (i = 0; i < tab->n_row; ++i) {
1331 if (isl_int_is_zero(tab->mat->row[i][2 + var->index]))
1333 isl_int_sub(tab->mat->row[i][1], tab->mat->row[i][1],
1334 tab->mat->row[i][2 + var->index]);
1339 push(tab, isl_tab_undo_relax, var);
1344 struct isl_tab *isl_tab_select_facet(struct isl_tab *tab, int con)
1349 return cut_to_hyperplane(tab, &tab->con[con]);
1352 static int may_be_equality(struct isl_tab *tab, int row)
1354 return (tab->rational ? isl_int_is_zero(tab->mat->row[row][1])
1355 : isl_int_lt(tab->mat->row[row][1],
1356 tab->mat->row[row][0])) &&
1357 isl_seq_first_non_zero(tab->mat->row[row] + 2 + tab->n_dead,
1358 tab->n_col - tab->n_dead) != -1;
1361 /* Check for (near) equalities among the constraints.
1362 * A constraint is an equality if it is non-negative and if
1363 * its maximal value is either
1364 * - zero (in case of rational tableaus), or
1365 * - strictly less than 1 (in case of integer tableaus)
1367 * We first mark all non-redundant and non-dead variables that
1368 * are not frozen and not obviously not an equality.
1369 * Then we iterate over all marked variables if they can attain
1370 * any values larger than zero or at least one.
1371 * If the maximal value is zero, we mark any column variables
1372 * that appear in the row as being zero and mark the row as being redundant.
1373 * Otherwise, if the maximal value is strictly less than one (and the
1374 * tableau is integer), then we restrict the value to being zero
1375 * by adding an opposite non-negative variable.
1377 struct isl_tab *isl_tab_detect_equalities(struct isl_tab *tab)
1386 if (tab->n_dead == tab->n_col)
1390 for (i = tab->n_redundant; i < tab->n_row; ++i) {
1391 struct isl_tab_var *var = var_from_row(tab, i);
1392 var->marked = !var->frozen && var->is_nonneg &&
1393 may_be_equality(tab, i);
1397 for (i = tab->n_dead; i < tab->n_col; ++i) {
1398 struct isl_tab_var *var = var_from_col(tab, i);
1399 var->marked = !var->frozen && var->is_nonneg;
1404 struct isl_tab_var *var;
1405 for (i = tab->n_redundant; i < tab->n_row; ++i) {
1406 var = var_from_row(tab, i);
1410 if (i == tab->n_row) {
1411 for (i = tab->n_dead; i < tab->n_col; ++i) {
1412 var = var_from_col(tab, i);
1416 if (i == tab->n_col)
1421 if (sign_of_max(tab, var) == 0)
1422 close_row(tab, var);
1423 else if (!tab->rational && !at_least_one(tab, var)) {
1424 tab = cut_to_hyperplane(tab, var);
1425 return isl_tab_detect_equalities(tab);
1427 for (i = tab->n_redundant; i < tab->n_row; ++i) {
1428 var = var_from_row(tab, i);
1431 if (may_be_equality(tab, i))
1441 /* Check for (near) redundant constraints.
1442 * A constraint is redundant if it is non-negative and if
1443 * its minimal value (temporarily ignoring the non-negativity) is either
1444 * - zero (in case of rational tableaus), or
1445 * - strictly larger than -1 (in case of integer tableaus)
1447 * We first mark all non-redundant and non-dead variables that
1448 * are not frozen and not obviously negatively unbounded.
1449 * Then we iterate over all marked variables if they can attain
1450 * any values smaller than zero or at most negative one.
1451 * If not, we mark the row as being redundant (assuming it hasn't
1452 * been detected as being obviously redundant in the mean time).
1454 struct isl_tab *isl_tab_detect_redundant(struct isl_tab *tab)
1463 if (tab->n_redundant == tab->n_row)
1467 for (i = tab->n_redundant; i < tab->n_row; ++i) {
1468 struct isl_tab_var *var = var_from_row(tab, i);
1469 var->marked = !var->frozen && var->is_nonneg;
1473 for (i = tab->n_dead; i < tab->n_col; ++i) {
1474 struct isl_tab_var *var = var_from_col(tab, i);
1475 var->marked = !var->frozen && var->is_nonneg &&
1476 !min_is_manifestly_unbounded(tab, var);
1481 struct isl_tab_var *var;
1482 for (i = tab->n_redundant; i < tab->n_row; ++i) {
1483 var = var_from_row(tab, i);
1487 if (i == tab->n_row) {
1488 for (i = tab->n_dead; i < tab->n_col; ++i) {
1489 var = var_from_col(tab, i);
1493 if (i == tab->n_col)
1498 if ((tab->rational ? (sign_of_min(tab, var) >= 0)
1499 : !min_at_most_neg_one(tab, var)) &&
1501 mark_redundant(tab, var->index);
1502 for (i = tab->n_dead; i < tab->n_col; ++i) {
1503 var = var_from_col(tab, i);
1506 if (!min_is_manifestly_unbounded(tab, var))
1516 int isl_tab_is_equality(struct isl_tab *tab, int con)
1522 if (tab->con[con].is_zero)
1524 if (tab->con[con].is_redundant)
1526 if (!tab->con[con].is_row)
1527 return tab->con[con].index < tab->n_dead;
1529 row = tab->con[con].index;
1531 return isl_int_is_zero(tab->mat->row[row][1]) &&
1532 isl_seq_first_non_zero(tab->mat->row[row] + 2 + tab->n_dead,
1533 tab->n_col - tab->n_dead) == -1;
1536 /* Return the minimial value of the affine expression "f" with denominator
1537 * "denom" in *opt, *opt_denom, assuming the tableau is not empty and
1538 * the expression cannot attain arbitrarily small values.
1539 * If opt_denom is NULL, then *opt is rounded up to the nearest integer.
1540 * The return value reflects the nature of the result (empty, unbounded,
1541 * minmimal value returned in *opt).
1543 enum isl_lp_result isl_tab_min(struct isl_tab *tab,
1544 isl_int *f, isl_int denom, isl_int *opt, isl_int *opt_denom,
1548 enum isl_lp_result res = isl_lp_ok;
1549 struct isl_tab_var *var;
1550 struct isl_tab_undo *snap;
1553 return isl_lp_empty;
1555 snap = isl_tab_snap(tab);
1556 r = add_row(tab, f);
1558 return isl_lp_error;
1560 isl_int_mul(tab->mat->row[var->index][0],
1561 tab->mat->row[var->index][0], denom);
1564 find_pivot(tab, var, var, -1, &row, &col);
1565 if (row == var->index) {
1566 res = isl_lp_unbounded;
1571 pivot(tab, row, col);
1573 if (isl_tab_rollback(tab, snap) < 0)
1574 return isl_lp_error;
1575 if (ISL_FL_ISSET(flags, ISL_TAB_SAVE_DUAL)) {
1578 isl_vec_free(tab->dual);
1579 tab->dual = isl_vec_alloc(tab->mat->ctx, 1 + tab->n_con);
1581 return isl_lp_error;
1582 isl_int_set(tab->dual->el[0], tab->mat->row[var->index][0]);
1583 for (i = 0; i < tab->n_con; ++i) {
1584 if (tab->con[i].is_row)
1585 isl_int_set_si(tab->dual->el[1 + i], 0);
1587 int pos = 2 + tab->con[i].index;
1588 isl_int_set(tab->dual->el[1 + i],
1589 tab->mat->row[var->index][pos]);
1593 if (res == isl_lp_ok) {
1595 isl_int_set(*opt, tab->mat->row[var->index][1]);
1596 isl_int_set(*opt_denom, tab->mat->row[var->index][0]);
1598 isl_int_cdiv_q(*opt, tab->mat->row[var->index][1],
1599 tab->mat->row[var->index][0]);
1604 int isl_tab_is_redundant(struct isl_tab *tab, int con)
1611 if (tab->con[con].is_zero)
1613 if (tab->con[con].is_redundant)
1615 return tab->con[con].is_row && tab->con[con].index < tab->n_redundant;
1618 /* Take a snapshot of the tableau that can be restored by s call to
1621 struct isl_tab_undo *isl_tab_snap(struct isl_tab *tab)
1629 /* Undo the operation performed by isl_tab_relax.
1631 static void unrelax(struct isl_tab *tab, struct isl_tab_var *var)
1633 if (!var->is_row && !max_is_manifestly_unbounded(tab, var))
1634 to_row(tab, var, 1);
1637 isl_int_sub(tab->mat->row[var->index][1],
1638 tab->mat->row[var->index][1], tab->mat->row[var->index][0]);
1642 for (i = 0; i < tab->n_row; ++i) {
1643 if (isl_int_is_zero(tab->mat->row[i][2 + var->index]))
1645 isl_int_add(tab->mat->row[i][1], tab->mat->row[i][1],
1646 tab->mat->row[i][2 + var->index]);
1652 static void perform_undo(struct isl_tab *tab, struct isl_tab_undo *undo)
1654 switch(undo->type) {
1655 case isl_tab_undo_empty:
1658 case isl_tab_undo_nonneg:
1659 undo->var->is_nonneg = 0;
1661 case isl_tab_undo_redundant:
1662 undo->var->is_redundant = 0;
1665 case isl_tab_undo_zero:
1666 undo->var->is_zero = 0;
1669 case isl_tab_undo_allocate:
1670 if (!undo->var->is_row) {
1671 if (max_is_manifestly_unbounded(tab, undo->var))
1672 to_row(tab, undo->var, -1);
1674 to_row(tab, undo->var, 1);
1676 drop_row(tab, undo->var->index);
1678 case isl_tab_undo_relax:
1679 unrelax(tab, undo->var);
1684 /* Return the tableau to the state it was in when the snapshot "snap"
1687 int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap)
1689 struct isl_tab_undo *undo, *next;
1695 for (undo = tab->top; undo && undo != &tab->bottom; undo = next) {
1699 perform_undo(tab, undo);
1709 /* The given row "row" represents an inequality violated by all
1710 * points in the tableau. Check for some special cases of such
1711 * separating constraints.
1712 * In particular, if the row has been reduced to the constant -1,
1713 * then we know the inequality is adjacent (but opposite) to
1714 * an equality in the tableau.
1715 * If the row has been reduced to r = -1 -r', with r' an inequality
1716 * of the tableau, then the inequality is adjacent (but opposite)
1717 * to the inequality r'.
1719 static enum isl_ineq_type separation_type(struct isl_tab *tab, unsigned row)
1724 return isl_ineq_separate;
1726 if (!isl_int_is_one(tab->mat->row[row][0]))
1727 return isl_ineq_separate;
1728 if (!isl_int_is_negone(tab->mat->row[row][1]))
1729 return isl_ineq_separate;
1731 pos = isl_seq_first_non_zero(tab->mat->row[row] + 2 + tab->n_dead,
1732 tab->n_col - tab->n_dead);
1734 return isl_ineq_adj_eq;
1736 if (!isl_int_is_negone(tab->mat->row[row][2 + tab->n_dead + pos]))
1737 return isl_ineq_separate;
1739 pos = isl_seq_first_non_zero(
1740 tab->mat->row[row] + 2 + tab->n_dead + pos + 1,
1741 tab->n_col - tab->n_dead - pos - 1);
1743 return pos == -1 ? isl_ineq_adj_ineq : isl_ineq_separate;
1746 /* Check the effect of inequality "ineq" on the tableau "tab".
1748 * isl_ineq_redundant: satisfied by all points in the tableau
1749 * isl_ineq_separate: satisfied by no point in the tableau
1750 * isl_ineq_cut: satisfied by some by not all points
1751 * isl_ineq_adj_eq: adjacent to an equality
1752 * isl_ineq_adj_ineq: adjacent to an inequality.
1754 enum isl_ineq_type isl_tab_ineq_type(struct isl_tab *tab, isl_int *ineq)
1756 enum isl_ineq_type type = isl_ineq_error;
1757 struct isl_tab_undo *snap = NULL;
1762 return isl_ineq_error;
1764 if (extend_cons(tab, 1) < 0)
1765 return isl_ineq_error;
1767 snap = isl_tab_snap(tab);
1769 con = add_row(tab, ineq);
1773 row = tab->con[con].index;
1774 if (is_redundant(tab, row))
1775 type = isl_ineq_redundant;
1776 else if (isl_int_is_neg(tab->mat->row[row][1]) &&
1778 isl_int_abs_ge(tab->mat->row[row][1],
1779 tab->mat->row[row][0]))) {
1780 if (at_least_zero(tab, &tab->con[con]))
1781 type = isl_ineq_cut;
1783 type = separation_type(tab, row);
1784 } else if (tab->rational ? (sign_of_min(tab, &tab->con[con]) < 0)
1785 : min_at_most_neg_one(tab, &tab->con[con]))
1786 type = isl_ineq_cut;
1788 type = isl_ineq_redundant;
1790 if (isl_tab_rollback(tab, snap))
1791 return isl_ineq_error;
1794 isl_tab_rollback(tab, snap);
1795 return isl_ineq_error;
1798 void isl_tab_dump(struct isl_tab *tab, FILE *out, int indent)
1804 fprintf(out, "%*snull tab\n", indent, "");
1807 fprintf(out, "%*sn_redundant: %d, n_dead: %d", indent, "",
1808 tab->n_redundant, tab->n_dead);
1810 fprintf(out, ", rational");
1812 fprintf(out, ", empty");
1814 fprintf(out, "%*s[", indent, "");
1815 for (i = 0; i < tab->n_var; ++i) {
1818 fprintf(out, "%c%d%s", tab->var[i].is_row ? 'r' : 'c',
1820 tab->var[i].is_zero ? " [=0]" :
1821 tab->var[i].is_redundant ? " [R]" : "");
1823 fprintf(out, "]\n");
1824 fprintf(out, "%*s[", indent, "");
1825 for (i = 0; i < tab->n_con; ++i) {
1828 fprintf(out, "%c%d%s", tab->con[i].is_row ? 'r' : 'c',
1830 tab->con[i].is_zero ? " [=0]" :
1831 tab->con[i].is_redundant ? " [R]" : "");
1833 fprintf(out, "]\n");
1834 fprintf(out, "%*s[", indent, "");
1835 for (i = 0; i < tab->n_row; ++i) {
1838 fprintf(out, "r%d: %d%s", i, tab->row_var[i],
1839 var_from_row(tab, i)->is_nonneg ? " [>=0]" : "");
1841 fprintf(out, "]\n");
1842 fprintf(out, "%*s[", indent, "");
1843 for (i = 0; i < tab->n_col; ++i) {
1846 fprintf(out, "c%d: %d%s", i, tab->col_var[i],
1847 var_from_col(tab, i)->is_nonneg ? " [>=0]" : "");
1849 fprintf(out, "]\n");
1850 r = tab->mat->n_row;
1851 tab->mat->n_row = tab->n_row;
1852 c = tab->mat->n_col;
1853 tab->mat->n_col = 2 + tab->n_col;
1854 isl_mat_dump(tab->mat, out, indent);
1855 tab->mat->n_row = r;
1856 tab->mat->n_col = c;