2 #include "isl_map_private.h"
7 * The implementation of tableaus in this file was inspired by Section 8
8 * of David Detlefs, Greg Nelson and James B. Saxe, "Simplify: a theorem
9 * prover for program checking".
12 struct isl_tab
*isl_tab_alloc(struct isl_ctx
*ctx
,
13 unsigned n_row
, unsigned n_var
, unsigned M
)
19 tab
= isl_calloc_type(ctx
, struct isl_tab
);
22 tab
->mat
= isl_mat_alloc(ctx
, n_row
, off
+ n_var
);
25 tab
->var
= isl_alloc_array(ctx
, struct isl_tab_var
, n_var
);
28 tab
->con
= isl_alloc_array(ctx
, struct isl_tab_var
, n_row
);
31 tab
->col_var
= isl_alloc_array(ctx
, int, n_var
);
34 tab
->row_var
= isl_alloc_array(ctx
, int, n_row
);
37 for (i
= 0; i
< n_var
; ++i
) {
38 tab
->var
[i
].index
= i
;
39 tab
->var
[i
].is_row
= 0;
40 tab
->var
[i
].is_nonneg
= 0;
41 tab
->var
[i
].is_zero
= 0;
42 tab
->var
[i
].is_redundant
= 0;
43 tab
->var
[i
].frozen
= 0;
44 tab
->var
[i
].negated
= 0;
63 tab
->bottom
.type
= isl_tab_undo_bottom
;
64 tab
->bottom
.next
= NULL
;
65 tab
->top
= &tab
->bottom
;
72 int isl_tab_extend_cons(struct isl_tab
*tab
, unsigned n_new
)
74 unsigned off
= 2 + tab
->M
;
75 if (tab
->max_con
< tab
->n_con
+ n_new
) {
76 struct isl_tab_var
*con
;
78 con
= isl_realloc_array(tab
->mat
->ctx
, tab
->con
,
79 struct isl_tab_var
, tab
->max_con
+ n_new
);
83 tab
->max_con
+= n_new
;
85 if (tab
->mat
->n_row
< tab
->n_row
+ n_new
) {
88 tab
->mat
= isl_mat_extend(tab
->mat
,
89 tab
->n_row
+ n_new
, off
+ tab
->n_col
);
92 row_var
= isl_realloc_array(tab
->mat
->ctx
, tab
->row_var
,
93 int, tab
->mat
->n_row
);
96 tab
->row_var
= row_var
;
98 enum isl_tab_row_sign
*s
;
99 s
= isl_realloc_array(tab
->mat
->ctx
, tab
->row_sign
,
100 enum isl_tab_row_sign
, tab
->mat
->n_row
);
109 /* Make room for at least n_new extra variables.
110 * Return -1 if anything went wrong.
112 int isl_tab_extend_vars(struct isl_tab
*tab
, unsigned n_new
)
114 struct isl_tab_var
*var
;
115 unsigned off
= 2 + tab
->M
;
117 if (tab
->max_var
< tab
->n_var
+ n_new
) {
118 var
= isl_realloc_array(tab
->mat
->ctx
, tab
->var
,
119 struct isl_tab_var
, tab
->n_var
+ n_new
);
123 tab
->max_var
+= n_new
;
126 if (tab
->mat
->n_col
< off
+ tab
->n_col
+ n_new
) {
129 tab
->mat
= isl_mat_extend(tab
->mat
,
130 tab
->mat
->n_row
, off
+ tab
->n_col
+ n_new
);
133 p
= isl_realloc_array(tab
->mat
->ctx
, tab
->col_var
,
134 int, tab
->n_col
+ n_new
);
143 struct isl_tab
*isl_tab_extend(struct isl_tab
*tab
, unsigned n_new
)
145 if (isl_tab_extend_cons(tab
, n_new
) >= 0)
152 static void free_undo(struct isl_tab
*tab
)
154 struct isl_tab_undo
*undo
, *next
;
156 for (undo
= tab
->top
; undo
&& undo
!= &tab
->bottom
; undo
= next
) {
163 void isl_tab_free(struct isl_tab
*tab
)
168 isl_mat_free(tab
->mat
);
169 isl_vec_free(tab
->dual
);
170 isl_basic_set_free(tab
->bset
);
176 isl_mat_free(tab
->samples
);
180 struct isl_tab
*isl_tab_dup(struct isl_tab
*tab
)
190 dup
= isl_calloc_type(tab
->ctx
, struct isl_tab
);
193 dup
->mat
= isl_mat_dup(tab
->mat
);
196 dup
->var
= isl_alloc_array(tab
->ctx
, struct isl_tab_var
, tab
->max_var
);
199 for (i
= 0; i
< tab
->n_var
; ++i
)
200 dup
->var
[i
] = tab
->var
[i
];
201 dup
->con
= isl_alloc_array(tab
->ctx
, struct isl_tab_var
, tab
->max_con
);
204 for (i
= 0; i
< tab
->n_con
; ++i
)
205 dup
->con
[i
] = tab
->con
[i
];
206 dup
->col_var
= isl_alloc_array(tab
->ctx
, int, tab
->mat
->n_col
- off
);
209 for (i
= 0; i
< tab
->n_col
; ++i
)
210 dup
->col_var
[i
] = tab
->col_var
[i
];
211 dup
->row_var
= isl_alloc_array(tab
->ctx
, int, tab
->mat
->n_row
);
214 for (i
= 0; i
< tab
->n_row
; ++i
)
215 dup
->row_var
[i
] = tab
->row_var
[i
];
217 dup
->row_sign
= isl_alloc_array(tab
->ctx
, enum isl_tab_row_sign
,
221 for (i
= 0; i
< tab
->n_row
; ++i
)
222 dup
->row_sign
[i
] = tab
->row_sign
[i
];
225 dup
->samples
= isl_mat_dup(tab
->samples
);
228 dup
->n_sample
= tab
->n_sample
;
229 dup
->n_outside
= tab
->n_outside
;
231 dup
->n_row
= tab
->n_row
;
232 dup
->n_con
= tab
->n_con
;
233 dup
->n_eq
= tab
->n_eq
;
234 dup
->max_con
= tab
->max_con
;
235 dup
->n_col
= tab
->n_col
;
236 dup
->n_var
= tab
->n_var
;
237 dup
->max_var
= tab
->max_var
;
238 dup
->n_param
= tab
->n_param
;
239 dup
->n_div
= tab
->n_div
;
240 dup
->n_dead
= tab
->n_dead
;
241 dup
->n_redundant
= tab
->n_redundant
;
242 dup
->rational
= tab
->rational
;
243 dup
->empty
= tab
->empty
;
247 dup
->bottom
.type
= isl_tab_undo_bottom
;
248 dup
->bottom
.next
= NULL
;
249 dup
->top
= &dup
->bottom
;
256 static struct isl_tab_var
*var_from_index(struct isl_tab
*tab
, int i
)
261 return &tab
->con
[~i
];
264 struct isl_tab_var
*isl_tab_var_from_row(struct isl_tab
*tab
, int i
)
266 return var_from_index(tab
, tab
->row_var
[i
]);
269 static struct isl_tab_var
*var_from_col(struct isl_tab
*tab
, int i
)
271 return var_from_index(tab
, tab
->col_var
[i
]);
274 /* Check if there are any upper bounds on column variable "var",
275 * i.e., non-negative rows where var appears with a negative coefficient.
276 * Return 1 if there are no such bounds.
278 static int max_is_manifestly_unbounded(struct isl_tab
*tab
,
279 struct isl_tab_var
*var
)
282 unsigned off
= 2 + tab
->M
;
286 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
287 if (!isl_int_is_neg(tab
->mat
->row
[i
][off
+ var
->index
]))
289 if (isl_tab_var_from_row(tab
, i
)->is_nonneg
)
295 /* Check if there are any lower bounds on column variable "var",
296 * i.e., non-negative rows where var appears with a positive coefficient.
297 * Return 1 if there are no such bounds.
299 static int min_is_manifestly_unbounded(struct isl_tab
*tab
,
300 struct isl_tab_var
*var
)
303 unsigned off
= 2 + tab
->M
;
307 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
308 if (!isl_int_is_pos(tab
->mat
->row
[i
][off
+ var
->index
]))
310 if (isl_tab_var_from_row(tab
, i
)->is_nonneg
)
316 static int row_cmp(struct isl_tab
*tab
, int r1
, int r2
, int c
, isl_int t
)
318 unsigned off
= 2 + tab
->M
;
322 isl_int_mul(t
, tab
->mat
->row
[r1
][2], tab
->mat
->row
[r2
][off
+c
]);
323 isl_int_submul(t
, tab
->mat
->row
[r2
][2], tab
->mat
->row
[r1
][off
+c
]);
328 isl_int_mul(t
, tab
->mat
->row
[r1
][1], tab
->mat
->row
[r2
][off
+ c
]);
329 isl_int_submul(t
, tab
->mat
->row
[r2
][1], tab
->mat
->row
[r1
][off
+ c
]);
330 return isl_int_sgn(t
);
333 /* Given the index of a column "c", return the index of a row
334 * that can be used to pivot the column in, with either an increase
335 * (sgn > 0) or a decrease (sgn < 0) of the corresponding variable.
336 * If "var" is not NULL, then the row returned will be different from
337 * the one associated with "var".
339 * Each row in the tableau is of the form
341 * x_r = a_r0 + \sum_i a_ri x_i
343 * Only rows with x_r >= 0 and with the sign of a_ri opposite to "sgn"
344 * impose any limit on the increase or decrease in the value of x_c
345 * and this bound is equal to a_r0 / |a_rc|. We are therefore looking
346 * for the row with the smallest (most stringent) such bound.
347 * Note that the common denominator of each row drops out of the fraction.
348 * To check if row j has a smaller bound than row r, i.e.,
349 * a_j0 / |a_jc| < a_r0 / |a_rc| or a_j0 |a_rc| < a_r0 |a_jc|,
350 * we check if -sign(a_jc) (a_j0 a_rc - a_r0 a_jc) < 0,
351 * where -sign(a_jc) is equal to "sgn".
353 static int pivot_row(struct isl_tab
*tab
,
354 struct isl_tab_var
*var
, int sgn
, int c
)
358 unsigned off
= 2 + tab
->M
;
362 for (j
= tab
->n_redundant
; j
< tab
->n_row
; ++j
) {
363 if (var
&& j
== var
->index
)
365 if (!isl_tab_var_from_row(tab
, j
)->is_nonneg
)
367 if (sgn
* isl_int_sgn(tab
->mat
->row
[j
][off
+ c
]) >= 0)
373 tsgn
= sgn
* row_cmp(tab
, r
, j
, c
, t
);
374 if (tsgn
< 0 || (tsgn
== 0 &&
375 tab
->row_var
[j
] < tab
->row_var
[r
]))
382 /* Find a pivot (row and col) that will increase (sgn > 0) or decrease
383 * (sgn < 0) the value of row variable var.
384 * If not NULL, then skip_var is a row variable that should be ignored
385 * while looking for a pivot row. It is usually equal to var.
387 * As the given row in the tableau is of the form
389 * x_r = a_r0 + \sum_i a_ri x_i
391 * we need to find a column such that the sign of a_ri is equal to "sgn"
392 * (such that an increase in x_i will have the desired effect) or a
393 * column with a variable that may attain negative values.
394 * If a_ri is positive, then we need to move x_i in the same direction
395 * to obtain the desired effect. Otherwise, x_i has to move in the
396 * opposite direction.
398 static void find_pivot(struct isl_tab
*tab
,
399 struct isl_tab_var
*var
, struct isl_tab_var
*skip_var
,
400 int sgn
, int *row
, int *col
)
407 isl_assert(tab
->mat
->ctx
, var
->is_row
, return);
408 tr
= tab
->mat
->row
[var
->index
] + 2 + tab
->M
;
411 for (j
= tab
->n_dead
; j
< tab
->n_col
; ++j
) {
412 if (isl_int_is_zero(tr
[j
]))
414 if (isl_int_sgn(tr
[j
]) != sgn
&&
415 var_from_col(tab
, j
)->is_nonneg
)
417 if (c
< 0 || tab
->col_var
[j
] < tab
->col_var
[c
])
423 sgn
*= isl_int_sgn(tr
[c
]);
424 r
= pivot_row(tab
, skip_var
, sgn
, c
);
425 *row
= r
< 0 ? var
->index
: r
;
429 /* Return 1 if row "row" represents an obviously redundant inequality.
431 * - it represents an inequality or a variable
432 * - that is the sum of a non-negative sample value and a positive
433 * combination of zero or more non-negative variables.
435 int isl_tab_row_is_redundant(struct isl_tab
*tab
, int row
)
438 unsigned off
= 2 + tab
->M
;
440 if (tab
->row_var
[row
] < 0 && !isl_tab_var_from_row(tab
, row
)->is_nonneg
)
443 if (isl_int_is_neg(tab
->mat
->row
[row
][1]))
445 if (tab
->M
&& isl_int_is_neg(tab
->mat
->row
[row
][2]))
448 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
) {
449 if (isl_int_is_zero(tab
->mat
->row
[row
][off
+ i
]))
451 if (isl_int_is_neg(tab
->mat
->row
[row
][off
+ i
]))
453 if (!var_from_col(tab
, i
)->is_nonneg
)
459 static void swap_rows(struct isl_tab
*tab
, int row1
, int row2
)
462 t
= tab
->row_var
[row1
];
463 tab
->row_var
[row1
] = tab
->row_var
[row2
];
464 tab
->row_var
[row2
] = t
;
465 isl_tab_var_from_row(tab
, row1
)->index
= row1
;
466 isl_tab_var_from_row(tab
, row2
)->index
= row2
;
467 tab
->mat
= isl_mat_swap_rows(tab
->mat
, row1
, row2
);
471 t
= tab
->row_sign
[row1
];
472 tab
->row_sign
[row1
] = tab
->row_sign
[row2
];
473 tab
->row_sign
[row2
] = t
;
476 static void push_union(struct isl_tab
*tab
,
477 enum isl_tab_undo_type type
, union isl_tab_undo_val u
)
479 struct isl_tab_undo
*undo
;
484 undo
= isl_alloc_type(tab
->mat
->ctx
, struct isl_tab_undo
);
492 undo
->next
= tab
->top
;
496 void isl_tab_push_var(struct isl_tab
*tab
,
497 enum isl_tab_undo_type type
, struct isl_tab_var
*var
)
499 union isl_tab_undo_val u
;
501 u
.var_index
= tab
->row_var
[var
->index
];
503 u
.var_index
= tab
->col_var
[var
->index
];
504 push_union(tab
, type
, u
);
507 void isl_tab_push(struct isl_tab
*tab
, enum isl_tab_undo_type type
)
509 union isl_tab_undo_val u
= { 0 };
510 push_union(tab
, type
, u
);
513 /* Push a record on the undo stack describing the current basic
514 * variables, so that the this state can be restored during rollback.
516 void isl_tab_push_basis(struct isl_tab
*tab
)
519 union isl_tab_undo_val u
;
521 u
.col_var
= isl_alloc_array(tab
->mat
->ctx
, int, tab
->n_col
);
527 for (i
= 0; i
< tab
->n_col
; ++i
)
528 u
.col_var
[i
] = tab
->col_var
[i
];
529 push_union(tab
, isl_tab_undo_saved_basis
, u
);
532 /* Mark row with index "row" as being redundant.
533 * If we may need to undo the operation or if the row represents
534 * a variable of the original problem, the row is kept,
535 * but no longer considered when looking for a pivot row.
536 * Otherwise, the row is simply removed.
538 * The row may be interchanged with some other row. If it
539 * is interchanged with a later row, return 1. Otherwise return 0.
540 * If the rows are checked in order in the calling function,
541 * then a return value of 1 means that the row with the given
542 * row number may now contain a different row that hasn't been checked yet.
544 int isl_tab_mark_redundant(struct isl_tab
*tab
, int row
)
546 struct isl_tab_var
*var
= isl_tab_var_from_row(tab
, row
);
547 var
->is_redundant
= 1;
548 isl_assert(tab
->mat
->ctx
, row
>= tab
->n_redundant
, return -1);
549 if (tab
->need_undo
|| tab
->row_var
[row
] >= 0) {
550 if (tab
->row_var
[row
] >= 0 && !var
->is_nonneg
) {
552 isl_tab_push_var(tab
, isl_tab_undo_nonneg
, var
);
554 if (row
!= tab
->n_redundant
)
555 swap_rows(tab
, row
, tab
->n_redundant
);
556 isl_tab_push_var(tab
, isl_tab_undo_redundant
, var
);
560 if (row
!= tab
->n_row
- 1)
561 swap_rows(tab
, row
, tab
->n_row
- 1);
562 isl_tab_var_from_row(tab
, tab
->n_row
- 1)->index
= -1;
568 struct isl_tab
*isl_tab_mark_empty(struct isl_tab
*tab
)
570 if (!tab
->empty
&& tab
->need_undo
)
571 isl_tab_push(tab
, isl_tab_undo_empty
);
576 /* Update the rows signs after a pivot of "row" and "col", with "row_sgn"
577 * the original sign of the pivot element.
578 * We only keep track of row signs during PILP solving and in this case
579 * we only pivot a row with negative sign (meaning the value is always
580 * non-positive) using a positive pivot element.
582 * For each row j, the new value of the parametric constant is equal to
584 * a_j0 - a_jc a_r0/a_rc
586 * where a_j0 is the original parametric constant, a_rc is the pivot element,
587 * a_r0 is the parametric constant of the pivot row and a_jc is the
588 * pivot column entry of the row j.
589 * Since a_r0 is non-positive and a_rc is positive, the sign of row j
590 * remains the same if a_jc has the same sign as the row j or if
591 * a_jc is zero. In all other cases, we reset the sign to "unknown".
593 static void update_row_sign(struct isl_tab
*tab
, int row
, int col
, int row_sgn
)
596 struct isl_mat
*mat
= tab
->mat
;
597 unsigned off
= 2 + tab
->M
;
602 if (tab
->row_sign
[row
] == 0)
604 isl_assert(mat
->ctx
, row_sgn
> 0, return);
605 isl_assert(mat
->ctx
, tab
->row_sign
[row
] == isl_tab_row_neg
, return);
606 tab
->row_sign
[row
] = isl_tab_row_pos
;
607 for (i
= 0; i
< tab
->n_row
; ++i
) {
611 s
= isl_int_sgn(mat
->row
[i
][off
+ col
]);
614 if (!tab
->row_sign
[i
])
616 if (s
< 0 && tab
->row_sign
[i
] == isl_tab_row_neg
)
618 if (s
> 0 && tab
->row_sign
[i
] == isl_tab_row_pos
)
620 tab
->row_sign
[i
] = isl_tab_row_unknown
;
624 /* Given a row number "row" and a column number "col", pivot the tableau
625 * such that the associated variables are interchanged.
626 * The given row in the tableau expresses
628 * x_r = a_r0 + \sum_i a_ri x_i
632 * x_c = 1/a_rc x_r - a_r0/a_rc + sum_{i \ne r} -a_ri/a_rc
634 * Substituting this equality into the other rows
636 * x_j = a_j0 + \sum_i a_ji x_i
638 * with a_jc \ne 0, we obtain
640 * 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
647 * where i is any other column and j is any other row,
648 * is therefore transformed into
650 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
651 * 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)
653 * The transformation is performed along the following steps
658 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
661 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
662 * n_jc/(|n_rc| d_j) n_ji/(|n_rc| d_j)
664 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
665 * n_jc/(|n_rc| d_j) (n_ji |n_rc|)/(|n_rc| d_j)
667 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
668 * n_jc/(|n_rc| d_j) (n_ji |n_rc| - s(n_rc)n_jc n_ri)/(|n_rc| d_j)
670 * s(n_rc)d_r/|n_rc| -s(n_rc)n_ri/|n_rc|
671 * 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)
674 void isl_tab_pivot(struct isl_tab
*tab
, int row
, int col
)
679 struct isl_mat
*mat
= tab
->mat
;
680 struct isl_tab_var
*var
;
681 unsigned off
= 2 + tab
->M
;
683 isl_int_swap(mat
->row
[row
][0], mat
->row
[row
][off
+ col
]);
684 sgn
= isl_int_sgn(mat
->row
[row
][0]);
686 isl_int_neg(mat
->row
[row
][0], mat
->row
[row
][0]);
687 isl_int_neg(mat
->row
[row
][off
+ col
], mat
->row
[row
][off
+ col
]);
689 for (j
= 0; j
< off
- 1 + tab
->n_col
; ++j
) {
690 if (j
== off
- 1 + col
)
692 isl_int_neg(mat
->row
[row
][1 + j
], mat
->row
[row
][1 + j
]);
694 if (!isl_int_is_one(mat
->row
[row
][0]))
695 isl_seq_normalize(mat
->ctx
, mat
->row
[row
], off
+ tab
->n_col
);
696 for (i
= 0; i
< tab
->n_row
; ++i
) {
699 if (isl_int_is_zero(mat
->row
[i
][off
+ col
]))
701 isl_int_mul(mat
->row
[i
][0], mat
->row
[i
][0], mat
->row
[row
][0]);
702 for (j
= 0; j
< off
- 1 + tab
->n_col
; ++j
) {
703 if (j
== off
- 1 + col
)
705 isl_int_mul(mat
->row
[i
][1 + j
],
706 mat
->row
[i
][1 + j
], mat
->row
[row
][0]);
707 isl_int_addmul(mat
->row
[i
][1 + j
],
708 mat
->row
[i
][off
+ col
], mat
->row
[row
][1 + j
]);
710 isl_int_mul(mat
->row
[i
][off
+ col
],
711 mat
->row
[i
][off
+ col
], mat
->row
[row
][off
+ col
]);
712 if (!isl_int_is_one(mat
->row
[i
][0]))
713 isl_seq_normalize(mat
->ctx
, mat
->row
[i
], off
+ tab
->n_col
);
715 t
= tab
->row_var
[row
];
716 tab
->row_var
[row
] = tab
->col_var
[col
];
717 tab
->col_var
[col
] = t
;
718 var
= isl_tab_var_from_row(tab
, row
);
721 var
= var_from_col(tab
, col
);
724 update_row_sign(tab
, row
, col
, sgn
);
727 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
728 if (isl_int_is_zero(mat
->row
[i
][off
+ col
]))
730 if (!isl_tab_var_from_row(tab
, i
)->frozen
&&
731 isl_tab_row_is_redundant(tab
, i
))
732 if (isl_tab_mark_redundant(tab
, i
))
737 /* If "var" represents a column variable, then pivot is up (sgn > 0)
738 * or down (sgn < 0) to a row. The variable is assumed not to be
739 * unbounded in the specified direction.
740 * If sgn = 0, then the variable is unbounded in both directions,
741 * and we pivot with any row we can find.
743 static void to_row(struct isl_tab
*tab
, struct isl_tab_var
*var
, int sign
)
746 unsigned off
= 2 + tab
->M
;
752 for (r
= tab
->n_redundant
; r
< tab
->n_row
; ++r
)
753 if (!isl_int_is_zero(tab
->mat
->row
[r
][off
+var
->index
]))
755 isl_assert(tab
->mat
->ctx
, r
< tab
->n_row
, return);
757 r
= pivot_row(tab
, NULL
, sign
, var
->index
);
758 isl_assert(tab
->mat
->ctx
, r
>= 0, return);
761 isl_tab_pivot(tab
, r
, var
->index
);
764 static void check_table(struct isl_tab
*tab
)
770 for (i
= 0; i
< tab
->n_row
; ++i
) {
771 if (!isl_tab_var_from_row(tab
, i
)->is_nonneg
)
773 assert(!isl_int_is_neg(tab
->mat
->row
[i
][1]));
777 /* Return the sign of the maximal value of "var".
778 * If the sign is not negative, then on return from this function,
779 * the sample value will also be non-negative.
781 * If "var" is manifestly unbounded wrt positive values, we are done.
782 * Otherwise, we pivot the variable up to a row if needed
783 * Then we continue pivoting down until either
784 * - no more down pivots can be performed
785 * - the sample value is positive
786 * - the variable is pivoted into a manifestly unbounded column
788 static int sign_of_max(struct isl_tab
*tab
, struct isl_tab_var
*var
)
792 if (max_is_manifestly_unbounded(tab
, var
))
795 while (!isl_int_is_pos(tab
->mat
->row
[var
->index
][1])) {
796 find_pivot(tab
, var
, var
, 1, &row
, &col
);
798 return isl_int_sgn(tab
->mat
->row
[var
->index
][1]);
799 isl_tab_pivot(tab
, row
, col
);
800 if (!var
->is_row
) /* manifestly unbounded */
806 static int row_is_neg(struct isl_tab
*tab
, int row
)
809 return isl_int_is_neg(tab
->mat
->row
[row
][1]);
810 if (isl_int_is_pos(tab
->mat
->row
[row
][2]))
812 if (isl_int_is_neg(tab
->mat
->row
[row
][2]))
814 return isl_int_is_neg(tab
->mat
->row
[row
][1]);
817 static int row_sgn(struct isl_tab
*tab
, int row
)
820 return isl_int_sgn(tab
->mat
->row
[row
][1]);
821 if (!isl_int_is_zero(tab
->mat
->row
[row
][2]))
822 return isl_int_sgn(tab
->mat
->row
[row
][2]);
824 return isl_int_sgn(tab
->mat
->row
[row
][1]);
827 /* Perform pivots until the row variable "var" has a non-negative
828 * sample value or until no more upward pivots can be performed.
829 * Return the sign of the sample value after the pivots have been
832 static int restore_row(struct isl_tab
*tab
, struct isl_tab_var
*var
)
836 while (row_is_neg(tab
, var
->index
)) {
837 find_pivot(tab
, var
, var
, 1, &row
, &col
);
840 isl_tab_pivot(tab
, row
, col
);
841 if (!var
->is_row
) /* manifestly unbounded */
844 return row_sgn(tab
, var
->index
);
847 /* Perform pivots until we are sure that the row variable "var"
848 * can attain non-negative values. After return from this
849 * function, "var" is still a row variable, but its sample
850 * value may not be non-negative, even if the function returns 1.
852 static int at_least_zero(struct isl_tab
*tab
, struct isl_tab_var
*var
)
856 while (isl_int_is_neg(tab
->mat
->row
[var
->index
][1])) {
857 find_pivot(tab
, var
, var
, 1, &row
, &col
);
860 if (row
== var
->index
) /* manifestly unbounded */
862 isl_tab_pivot(tab
, row
, col
);
864 return !isl_int_is_neg(tab
->mat
->row
[var
->index
][1]);
867 /* Return a negative value if "var" can attain negative values.
868 * Return a non-negative value otherwise.
870 * If "var" is manifestly unbounded wrt negative values, we are done.
871 * Otherwise, if var is in a column, we can pivot it down to a row.
872 * Then we continue pivoting down until either
873 * - the pivot would result in a manifestly unbounded column
874 * => we don't perform the pivot, but simply return -1
875 * - no more down pivots can be performed
876 * - the sample value is negative
877 * If the sample value becomes negative and the variable is supposed
878 * to be nonnegative, then we undo the last pivot.
879 * However, if the last pivot has made the pivoting variable
880 * obviously redundant, then it may have moved to another row.
881 * In that case we look for upward pivots until we reach a non-negative
884 static int sign_of_min(struct isl_tab
*tab
, struct isl_tab_var
*var
)
887 struct isl_tab_var
*pivot_var
= NULL
;
889 if (min_is_manifestly_unbounded(tab
, var
))
893 row
= pivot_row(tab
, NULL
, -1, col
);
894 pivot_var
= var_from_col(tab
, col
);
895 isl_tab_pivot(tab
, row
, col
);
896 if (var
->is_redundant
)
898 if (isl_int_is_neg(tab
->mat
->row
[var
->index
][1])) {
899 if (var
->is_nonneg
) {
900 if (!pivot_var
->is_redundant
&&
901 pivot_var
->index
== row
)
902 isl_tab_pivot(tab
, row
, col
);
904 restore_row(tab
, var
);
909 if (var
->is_redundant
)
911 while (!isl_int_is_neg(tab
->mat
->row
[var
->index
][1])) {
912 find_pivot(tab
, var
, var
, -1, &row
, &col
);
913 if (row
== var
->index
)
916 return isl_int_sgn(tab
->mat
->row
[var
->index
][1]);
917 pivot_var
= var_from_col(tab
, col
);
918 isl_tab_pivot(tab
, row
, col
);
919 if (var
->is_redundant
)
922 if (pivot_var
&& var
->is_nonneg
) {
923 /* pivot back to non-negative value */
924 if (!pivot_var
->is_redundant
&& pivot_var
->index
== row
)
925 isl_tab_pivot(tab
, row
, col
);
927 restore_row(tab
, var
);
932 static int row_at_most_neg_one(struct isl_tab
*tab
, int row
)
935 if (isl_int_is_pos(tab
->mat
->row
[row
][2]))
937 if (isl_int_is_neg(tab
->mat
->row
[row
][2]))
940 return isl_int_is_neg(tab
->mat
->row
[row
][1]) &&
941 isl_int_abs_ge(tab
->mat
->row
[row
][1],
942 tab
->mat
->row
[row
][0]);
945 /* Return 1 if "var" can attain values <= -1.
946 * Return 0 otherwise.
948 * The sample value of "var" is assumed to be non-negative when the
949 * the function is called and will be made non-negative again before
950 * the function returns.
952 int isl_tab_min_at_most_neg_one(struct isl_tab
*tab
, struct isl_tab_var
*var
)
955 struct isl_tab_var
*pivot_var
;
957 if (min_is_manifestly_unbounded(tab
, var
))
961 row
= pivot_row(tab
, NULL
, -1, col
);
962 pivot_var
= var_from_col(tab
, col
);
963 isl_tab_pivot(tab
, row
, col
);
964 if (var
->is_redundant
)
966 if (row_at_most_neg_one(tab
, var
->index
)) {
967 if (var
->is_nonneg
) {
968 if (!pivot_var
->is_redundant
&&
969 pivot_var
->index
== row
)
970 isl_tab_pivot(tab
, row
, col
);
972 restore_row(tab
, var
);
977 if (var
->is_redundant
)
980 find_pivot(tab
, var
, var
, -1, &row
, &col
);
981 if (row
== var
->index
)
985 pivot_var
= var_from_col(tab
, col
);
986 isl_tab_pivot(tab
, row
, col
);
987 if (var
->is_redundant
)
989 } while (!row_at_most_neg_one(tab
, var
->index
));
990 if (var
->is_nonneg
) {
991 /* pivot back to non-negative value */
992 if (!pivot_var
->is_redundant
&& pivot_var
->index
== row
)
993 isl_tab_pivot(tab
, row
, col
);
994 restore_row(tab
, var
);
999 /* Return 1 if "var" can attain values >= 1.
1000 * Return 0 otherwise.
1002 static int at_least_one(struct isl_tab
*tab
, struct isl_tab_var
*var
)
1007 if (max_is_manifestly_unbounded(tab
, var
))
1009 to_row(tab
, var
, 1);
1010 r
= tab
->mat
->row
[var
->index
];
1011 while (isl_int_lt(r
[1], r
[0])) {
1012 find_pivot(tab
, var
, var
, 1, &row
, &col
);
1014 return isl_int_ge(r
[1], r
[0]);
1015 if (row
== var
->index
) /* manifestly unbounded */
1017 isl_tab_pivot(tab
, row
, col
);
1022 static void swap_cols(struct isl_tab
*tab
, int col1
, int col2
)
1025 unsigned off
= 2 + tab
->M
;
1026 t
= tab
->col_var
[col1
];
1027 tab
->col_var
[col1
] = tab
->col_var
[col2
];
1028 tab
->col_var
[col2
] = t
;
1029 var_from_col(tab
, col1
)->index
= col1
;
1030 var_from_col(tab
, col2
)->index
= col2
;
1031 tab
->mat
= isl_mat_swap_cols(tab
->mat
, off
+ col1
, off
+ col2
);
1034 /* Mark column with index "col" as representing a zero variable.
1035 * If we may need to undo the operation the column is kept,
1036 * but no longer considered.
1037 * Otherwise, the column is simply removed.
1039 * The column may be interchanged with some other column. If it
1040 * is interchanged with a later column, return 1. Otherwise return 0.
1041 * If the columns are checked in order in the calling function,
1042 * then a return value of 1 means that the column with the given
1043 * column number may now contain a different column that
1044 * hasn't been checked yet.
1046 int isl_tab_kill_col(struct isl_tab
*tab
, int col
)
1048 var_from_col(tab
, col
)->is_zero
= 1;
1049 if (tab
->need_undo
) {
1050 isl_tab_push_var(tab
, isl_tab_undo_zero
, var_from_col(tab
, col
));
1051 if (col
!= tab
->n_dead
)
1052 swap_cols(tab
, col
, tab
->n_dead
);
1056 if (col
!= tab
->n_col
- 1)
1057 swap_cols(tab
, col
, tab
->n_col
- 1);
1058 var_from_col(tab
, tab
->n_col
- 1)->index
= -1;
1064 /* Row variable "var" is non-negative and cannot attain any values
1065 * larger than zero. This means that the coefficients of the unrestricted
1066 * column variables are zero and that the coefficients of the non-negative
1067 * column variables are zero or negative.
1068 * Each of the non-negative variables with a negative coefficient can
1069 * then also be written as the negative sum of non-negative variables
1070 * and must therefore also be zero.
1072 static void close_row(struct isl_tab
*tab
, struct isl_tab_var
*var
)
1075 struct isl_mat
*mat
= tab
->mat
;
1076 unsigned off
= 2 + tab
->M
;
1078 isl_assert(tab
->mat
->ctx
, var
->is_nonneg
, return);
1080 for (j
= tab
->n_dead
; j
< tab
->n_col
; ++j
) {
1081 if (isl_int_is_zero(mat
->row
[var
->index
][off
+ j
]))
1083 isl_assert(tab
->mat
->ctx
,
1084 isl_int_is_neg(mat
->row
[var
->index
][off
+ j
]), return);
1085 if (isl_tab_kill_col(tab
, j
))
1088 isl_tab_mark_redundant(tab
, var
->index
);
1091 /* Add a constraint to the tableau and allocate a row for it.
1092 * Return the index into the constraint array "con".
1094 int isl_tab_allocate_con(struct isl_tab
*tab
)
1098 isl_assert(tab
->mat
->ctx
, tab
->n_row
< tab
->mat
->n_row
, return -1);
1101 tab
->con
[r
].index
= tab
->n_row
;
1102 tab
->con
[r
].is_row
= 1;
1103 tab
->con
[r
].is_nonneg
= 0;
1104 tab
->con
[r
].is_zero
= 0;
1105 tab
->con
[r
].is_redundant
= 0;
1106 tab
->con
[r
].frozen
= 0;
1107 tab
->con
[r
].negated
= 0;
1108 tab
->row_var
[tab
->n_row
] = ~r
;
1112 isl_tab_push_var(tab
, isl_tab_undo_allocate
, &tab
->con
[r
]);
1117 /* Add a variable to the tableau and allocate a column for it.
1118 * Return the index into the variable array "var".
1120 int isl_tab_allocate_var(struct isl_tab
*tab
)
1124 unsigned off
= 2 + tab
->M
;
1126 isl_assert(tab
->mat
->ctx
, tab
->n_col
< tab
->mat
->n_col
, return -1);
1127 isl_assert(tab
->mat
->ctx
, tab
->n_var
< tab
->max_var
, return -1);
1130 tab
->var
[r
].index
= tab
->n_col
;
1131 tab
->var
[r
].is_row
= 0;
1132 tab
->var
[r
].is_nonneg
= 0;
1133 tab
->var
[r
].is_zero
= 0;
1134 tab
->var
[r
].is_redundant
= 0;
1135 tab
->var
[r
].frozen
= 0;
1136 tab
->var
[r
].negated
= 0;
1137 tab
->col_var
[tab
->n_col
] = r
;
1139 for (i
= 0; i
< tab
->n_row
; ++i
)
1140 isl_int_set_si(tab
->mat
->row
[i
][off
+ tab
->n_col
], 0);
1144 isl_tab_push_var(tab
, isl_tab_undo_allocate
, &tab
->var
[r
]);
1149 /* Add a row to the tableau. The row is given as an affine combination
1150 * of the original variables and needs to be expressed in terms of the
1153 * We add each term in turn.
1154 * If r = n/d_r is the current sum and we need to add k x, then
1155 * if x is a column variable, we increase the numerator of
1156 * this column by k d_r
1157 * if x = f/d_x is a row variable, then the new representation of r is
1159 * n k f d_x/g n + d_r/g k f m/d_r n + m/d_g k f
1160 * --- + --- = ------------------- = -------------------
1161 * d_r d_r d_r d_x/g m
1163 * with g the gcd of d_r and d_x and m the lcm of d_r and d_x.
1165 int isl_tab_add_row(struct isl_tab
*tab
, isl_int
*line
)
1171 unsigned off
= 2 + tab
->M
;
1173 r
= isl_tab_allocate_con(tab
);
1179 row
= tab
->mat
->row
[tab
->con
[r
].index
];
1180 isl_int_set_si(row
[0], 1);
1181 isl_int_set(row
[1], line
[0]);
1182 isl_seq_clr(row
+ 2, tab
->M
+ tab
->n_col
);
1183 for (i
= 0; i
< tab
->n_var
; ++i
) {
1184 if (tab
->var
[i
].is_zero
)
1186 if (tab
->var
[i
].is_row
) {
1188 row
[0], tab
->mat
->row
[tab
->var
[i
].index
][0]);
1189 isl_int_swap(a
, row
[0]);
1190 isl_int_divexact(a
, row
[0], a
);
1192 row
[0], tab
->mat
->row
[tab
->var
[i
].index
][0]);
1193 isl_int_mul(b
, b
, line
[1 + i
]);
1194 isl_seq_combine(row
+ 1, a
, row
+ 1,
1195 b
, tab
->mat
->row
[tab
->var
[i
].index
] + 1,
1196 1 + tab
->M
+ tab
->n_col
);
1198 isl_int_addmul(row
[off
+ tab
->var
[i
].index
],
1199 line
[1 + i
], row
[0]);
1200 if (tab
->M
&& i
>= tab
->n_param
&& i
< tab
->n_var
- tab
->n_div
)
1201 isl_int_submul(row
[2], line
[1 + i
], row
[0]);
1203 isl_seq_normalize(tab
->mat
->ctx
, row
, off
+ tab
->n_col
);
1208 tab
->row_sign
[tab
->con
[r
].index
] = 0;
1213 static int drop_row(struct isl_tab
*tab
, int row
)
1215 isl_assert(tab
->mat
->ctx
, ~tab
->row_var
[row
] == tab
->n_con
- 1, return -1);
1216 if (row
!= tab
->n_row
- 1)
1217 swap_rows(tab
, row
, tab
->n_row
- 1);
1223 static int drop_col(struct isl_tab
*tab
, int col
)
1225 isl_assert(tab
->mat
->ctx
, tab
->col_var
[col
] == tab
->n_var
- 1, return -1);
1226 if (col
!= tab
->n_col
- 1)
1227 swap_cols(tab
, col
, tab
->n_col
- 1);
1233 /* Add inequality "ineq" and check if it conflicts with the
1234 * previously added constraints or if it is obviously redundant.
1236 struct isl_tab
*isl_tab_add_ineq(struct isl_tab
*tab
, isl_int
*ineq
)
1243 r
= isl_tab_add_row(tab
, ineq
);
1246 tab
->con
[r
].is_nonneg
= 1;
1247 isl_tab_push_var(tab
, isl_tab_undo_nonneg
, &tab
->con
[r
]);
1248 if (isl_tab_row_is_redundant(tab
, tab
->con
[r
].index
)) {
1249 isl_tab_mark_redundant(tab
, tab
->con
[r
].index
);
1253 sgn
= restore_row(tab
, &tab
->con
[r
]);
1255 return isl_tab_mark_empty(tab
);
1256 if (tab
->con
[r
].is_row
&& isl_tab_row_is_redundant(tab
, tab
->con
[r
].index
))
1257 isl_tab_mark_redundant(tab
, tab
->con
[r
].index
);
1264 /* Pivot a non-negative variable down until it reaches the value zero
1265 * and then pivot the variable into a column position.
1267 static int to_col(struct isl_tab
*tab
, struct isl_tab_var
*var
)
1271 unsigned off
= 2 + tab
->M
;
1276 while (isl_int_is_pos(tab
->mat
->row
[var
->index
][1])) {
1277 find_pivot(tab
, var
, NULL
, -1, &row
, &col
);
1278 isl_assert(tab
->mat
->ctx
, row
!= -1, return -1);
1279 isl_tab_pivot(tab
, row
, col
);
1284 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
)
1285 if (!isl_int_is_zero(tab
->mat
->row
[var
->index
][off
+ i
]))
1288 isl_assert(tab
->mat
->ctx
, i
< tab
->n_col
, return -1);
1289 isl_tab_pivot(tab
, var
->index
, i
);
1294 /* We assume Gaussian elimination has been performed on the equalities.
1295 * The equalities can therefore never conflict.
1296 * Adding the equalities is currently only really useful for a later call
1297 * to isl_tab_ineq_type.
1299 static struct isl_tab
*add_eq(struct isl_tab
*tab
, isl_int
*eq
)
1306 r
= isl_tab_add_row(tab
, eq
);
1310 r
= tab
->con
[r
].index
;
1311 i
= isl_seq_first_non_zero(tab
->mat
->row
[r
] + 2 + tab
->M
+ tab
->n_dead
,
1312 tab
->n_col
- tab
->n_dead
);
1313 isl_assert(tab
->mat
->ctx
, i
>= 0, goto error
);
1315 isl_tab_pivot(tab
, r
, i
);
1316 isl_tab_kill_col(tab
, i
);
1325 /* Add an equality that is known to be valid for the given tableau.
1327 struct isl_tab
*isl_tab_add_valid_eq(struct isl_tab
*tab
, isl_int
*eq
)
1329 struct isl_tab_var
*var
;
1334 r
= isl_tab_add_row(tab
, eq
);
1340 if (isl_int_is_neg(tab
->mat
->row
[r
][1])) {
1341 isl_seq_neg(tab
->mat
->row
[r
] + 1, tab
->mat
->row
[r
] + 1,
1346 if (to_col(tab
, var
) < 0)
1349 isl_tab_kill_col(tab
, var
->index
);
1357 struct isl_tab
*isl_tab_from_basic_map(struct isl_basic_map
*bmap
)
1360 struct isl_tab
*tab
;
1364 tab
= isl_tab_alloc(bmap
->ctx
,
1365 isl_basic_map_total_dim(bmap
) + bmap
->n_ineq
+ 1,
1366 isl_basic_map_total_dim(bmap
), 0);
1369 tab
->rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
1370 if (ISL_F_ISSET(bmap
, ISL_BASIC_MAP_EMPTY
))
1371 return isl_tab_mark_empty(tab
);
1372 for (i
= 0; i
< bmap
->n_eq
; ++i
) {
1373 tab
= add_eq(tab
, bmap
->eq
[i
]);
1377 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
1378 tab
= isl_tab_add_ineq(tab
, bmap
->ineq
[i
]);
1379 if (!tab
|| tab
->empty
)
1385 struct isl_tab
*isl_tab_from_basic_set(struct isl_basic_set
*bset
)
1387 return isl_tab_from_basic_map((struct isl_basic_map
*)bset
);
1390 /* Construct a tableau corresponding to the recession cone of "bmap".
1392 struct isl_tab
*isl_tab_from_recession_cone(struct isl_basic_map
*bmap
)
1396 struct isl_tab
*tab
;
1400 tab
= isl_tab_alloc(bmap
->ctx
, bmap
->n_eq
+ bmap
->n_ineq
,
1401 isl_basic_map_total_dim(bmap
), 0);
1404 tab
->rational
= ISL_F_ISSET(bmap
, ISL_BASIC_MAP_RATIONAL
);
1407 for (i
= 0; i
< bmap
->n_eq
; ++i
) {
1408 isl_int_swap(bmap
->eq
[i
][0], cst
);
1409 tab
= add_eq(tab
, bmap
->eq
[i
]);
1410 isl_int_swap(bmap
->eq
[i
][0], cst
);
1414 for (i
= 0; i
< bmap
->n_ineq
; ++i
) {
1416 isl_int_swap(bmap
->ineq
[i
][0], cst
);
1417 r
= isl_tab_add_row(tab
, bmap
->ineq
[i
]);
1418 isl_int_swap(bmap
->ineq
[i
][0], cst
);
1421 tab
->con
[r
].is_nonneg
= 1;
1422 isl_tab_push_var(tab
, isl_tab_undo_nonneg
, &tab
->con
[r
]);
1433 /* Assuming "tab" is the tableau of a cone, check if the cone is
1434 * bounded, i.e., if it is empty or only contains the origin.
1436 int isl_tab_cone_is_bounded(struct isl_tab
*tab
)
1444 if (tab
->n_dead
== tab
->n_col
)
1448 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
1449 struct isl_tab_var
*var
;
1450 var
= isl_tab_var_from_row(tab
, i
);
1451 if (!var
->is_nonneg
)
1453 if (sign_of_max(tab
, var
) != 0)
1455 close_row(tab
, var
);
1458 if (tab
->n_dead
== tab
->n_col
)
1460 if (i
== tab
->n_row
)
1465 int isl_tab_sample_is_integer(struct isl_tab
*tab
)
1472 for (i
= 0; i
< tab
->n_var
; ++i
) {
1474 if (!tab
->var
[i
].is_row
)
1476 row
= tab
->var
[i
].index
;
1477 if (!isl_int_is_divisible_by(tab
->mat
->row
[row
][1],
1478 tab
->mat
->row
[row
][0]))
1484 static struct isl_vec
*extract_integer_sample(struct isl_tab
*tab
)
1487 struct isl_vec
*vec
;
1489 vec
= isl_vec_alloc(tab
->mat
->ctx
, 1 + tab
->n_var
);
1493 isl_int_set_si(vec
->block
.data
[0], 1);
1494 for (i
= 0; i
< tab
->n_var
; ++i
) {
1495 if (!tab
->var
[i
].is_row
)
1496 isl_int_set_si(vec
->block
.data
[1 + i
], 0);
1498 int row
= tab
->var
[i
].index
;
1499 isl_int_divexact(vec
->block
.data
[1 + i
],
1500 tab
->mat
->row
[row
][1], tab
->mat
->row
[row
][0]);
1507 struct isl_vec
*isl_tab_get_sample_value(struct isl_tab
*tab
)
1510 struct isl_vec
*vec
;
1516 vec
= isl_vec_alloc(tab
->mat
->ctx
, 1 + tab
->n_var
);
1522 isl_int_set_si(vec
->block
.data
[0], 1);
1523 for (i
= 0; i
< tab
->n_var
; ++i
) {
1525 if (!tab
->var
[i
].is_row
) {
1526 isl_int_set_si(vec
->block
.data
[1 + i
], 0);
1529 row
= tab
->var
[i
].index
;
1530 isl_int_gcd(m
, vec
->block
.data
[0], tab
->mat
->row
[row
][0]);
1531 isl_int_divexact(m
, tab
->mat
->row
[row
][0], m
);
1532 isl_seq_scale(vec
->block
.data
, vec
->block
.data
, m
, 1 + i
);
1533 isl_int_divexact(m
, vec
->block
.data
[0], tab
->mat
->row
[row
][0]);
1534 isl_int_mul(vec
->block
.data
[1 + i
], m
, tab
->mat
->row
[row
][1]);
1536 vec
= isl_vec_normalize(vec
);
1542 /* Update "bmap" based on the results of the tableau "tab".
1543 * In particular, implicit equalities are made explicit, redundant constraints
1544 * are removed and if the sample value happens to be integer, it is stored
1545 * in "bmap" (unless "bmap" already had an integer sample).
1547 * The tableau is assumed to have been created from "bmap" using
1548 * isl_tab_from_basic_map.
1550 struct isl_basic_map
*isl_basic_map_update_from_tab(struct isl_basic_map
*bmap
,
1551 struct isl_tab
*tab
)
1563 bmap
= isl_basic_map_set_to_empty(bmap
);
1565 for (i
= bmap
->n_ineq
- 1; i
>= 0; --i
) {
1566 if (isl_tab_is_equality(tab
, n_eq
+ i
))
1567 isl_basic_map_inequality_to_equality(bmap
, i
);
1568 else if (isl_tab_is_redundant(tab
, n_eq
+ i
))
1569 isl_basic_map_drop_inequality(bmap
, i
);
1571 if (!tab
->rational
&&
1572 !bmap
->sample
&& isl_tab_sample_is_integer(tab
))
1573 bmap
->sample
= extract_integer_sample(tab
);
1577 struct isl_basic_set
*isl_basic_set_update_from_tab(struct isl_basic_set
*bset
,
1578 struct isl_tab
*tab
)
1580 return (struct isl_basic_set
*)isl_basic_map_update_from_tab(
1581 (struct isl_basic_map
*)bset
, tab
);
1584 /* Given a non-negative variable "var", add a new non-negative variable
1585 * that is the opposite of "var", ensuring that var can only attain the
1587 * If var = n/d is a row variable, then the new variable = -n/d.
1588 * If var is a column variables, then the new variable = -var.
1589 * If the new variable cannot attain non-negative values, then
1590 * the resulting tableau is empty.
1591 * Otherwise, we know the value will be zero and we close the row.
1593 static struct isl_tab
*cut_to_hyperplane(struct isl_tab
*tab
,
1594 struct isl_tab_var
*var
)
1599 unsigned off
= 2 + tab
->M
;
1603 isl_assert(tab
->mat
->ctx
, !var
->is_redundant
, goto error
);
1605 if (isl_tab_extend_cons(tab
, 1) < 0)
1609 tab
->con
[r
].index
= tab
->n_row
;
1610 tab
->con
[r
].is_row
= 1;
1611 tab
->con
[r
].is_nonneg
= 0;
1612 tab
->con
[r
].is_zero
= 0;
1613 tab
->con
[r
].is_redundant
= 0;
1614 tab
->con
[r
].frozen
= 0;
1615 tab
->con
[r
].negated
= 0;
1616 tab
->row_var
[tab
->n_row
] = ~r
;
1617 row
= tab
->mat
->row
[tab
->n_row
];
1620 isl_int_set(row
[0], tab
->mat
->row
[var
->index
][0]);
1621 isl_seq_neg(row
+ 1,
1622 tab
->mat
->row
[var
->index
] + 1, 1 + tab
->n_col
);
1624 isl_int_set_si(row
[0], 1);
1625 isl_seq_clr(row
+ 1, 1 + tab
->n_col
);
1626 isl_int_set_si(row
[off
+ var
->index
], -1);
1631 isl_tab_push_var(tab
, isl_tab_undo_allocate
, &tab
->con
[r
]);
1633 sgn
= sign_of_max(tab
, &tab
->con
[r
]);
1635 return isl_tab_mark_empty(tab
);
1636 tab
->con
[r
].is_nonneg
= 1;
1637 isl_tab_push_var(tab
, isl_tab_undo_nonneg
, &tab
->con
[r
]);
1639 close_row(tab
, &tab
->con
[r
]);
1647 /* Given a tableau "tab" and an inequality constraint "con" of the tableau,
1648 * relax the inequality by one. That is, the inequality r >= 0 is replaced
1649 * by r' = r + 1 >= 0.
1650 * If r is a row variable, we simply increase the constant term by one
1651 * (taking into account the denominator).
1652 * If r is a column variable, then we need to modify each row that
1653 * refers to r = r' - 1 by substituting this equality, effectively
1654 * subtracting the coefficient of the column from the constant.
1656 struct isl_tab
*isl_tab_relax(struct isl_tab
*tab
, int con
)
1658 struct isl_tab_var
*var
;
1659 unsigned off
= 2 + tab
->M
;
1664 var
= &tab
->con
[con
];
1666 if (!var
->is_row
&& !max_is_manifestly_unbounded(tab
, var
))
1667 to_row(tab
, var
, 1);
1670 isl_int_add(tab
->mat
->row
[var
->index
][1],
1671 tab
->mat
->row
[var
->index
][1], tab
->mat
->row
[var
->index
][0]);
1675 for (i
= 0; i
< tab
->n_row
; ++i
) {
1676 if (isl_int_is_zero(tab
->mat
->row
[i
][off
+ var
->index
]))
1678 isl_int_sub(tab
->mat
->row
[i
][1], tab
->mat
->row
[i
][1],
1679 tab
->mat
->row
[i
][off
+ var
->index
]);
1684 isl_tab_push_var(tab
, isl_tab_undo_relax
, var
);
1689 struct isl_tab
*isl_tab_select_facet(struct isl_tab
*tab
, int con
)
1694 return cut_to_hyperplane(tab
, &tab
->con
[con
]);
1697 static int may_be_equality(struct isl_tab
*tab
, int row
)
1699 unsigned off
= 2 + tab
->M
;
1700 return (tab
->rational
? isl_int_is_zero(tab
->mat
->row
[row
][1])
1701 : isl_int_lt(tab
->mat
->row
[row
][1],
1702 tab
->mat
->row
[row
][0])) &&
1703 isl_seq_first_non_zero(tab
->mat
->row
[row
] + off
+ tab
->n_dead
,
1704 tab
->n_col
- tab
->n_dead
) != -1;
1707 /* Check for (near) equalities among the constraints.
1708 * A constraint is an equality if it is non-negative and if
1709 * its maximal value is either
1710 * - zero (in case of rational tableaus), or
1711 * - strictly less than 1 (in case of integer tableaus)
1713 * We first mark all non-redundant and non-dead variables that
1714 * are not frozen and not obviously not an equality.
1715 * Then we iterate over all marked variables if they can attain
1716 * any values larger than zero or at least one.
1717 * If the maximal value is zero, we mark any column variables
1718 * that appear in the row as being zero and mark the row as being redundant.
1719 * Otherwise, if the maximal value is strictly less than one (and the
1720 * tableau is integer), then we restrict the value to being zero
1721 * by adding an opposite non-negative variable.
1723 struct isl_tab
*isl_tab_detect_equalities(struct isl_tab
*tab
)
1732 if (tab
->n_dead
== tab
->n_col
)
1736 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
1737 struct isl_tab_var
*var
= isl_tab_var_from_row(tab
, i
);
1738 var
->marked
= !var
->frozen
&& var
->is_nonneg
&&
1739 may_be_equality(tab
, i
);
1743 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
) {
1744 struct isl_tab_var
*var
= var_from_col(tab
, i
);
1745 var
->marked
= !var
->frozen
&& var
->is_nonneg
;
1750 struct isl_tab_var
*var
;
1751 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
1752 var
= isl_tab_var_from_row(tab
, i
);
1756 if (i
== tab
->n_row
) {
1757 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
) {
1758 var
= var_from_col(tab
, i
);
1762 if (i
== tab
->n_col
)
1767 if (sign_of_max(tab
, var
) == 0)
1768 close_row(tab
, var
);
1769 else if (!tab
->rational
&& !at_least_one(tab
, var
)) {
1770 tab
= cut_to_hyperplane(tab
, var
);
1771 return isl_tab_detect_equalities(tab
);
1773 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
1774 var
= isl_tab_var_from_row(tab
, i
);
1777 if (may_be_equality(tab
, i
))
1787 /* Check for (near) redundant constraints.
1788 * A constraint is redundant if it is non-negative and if
1789 * its minimal value (temporarily ignoring the non-negativity) is either
1790 * - zero (in case of rational tableaus), or
1791 * - strictly larger than -1 (in case of integer tableaus)
1793 * We first mark all non-redundant and non-dead variables that
1794 * are not frozen and not obviously negatively unbounded.
1795 * Then we iterate over all marked variables if they can attain
1796 * any values smaller than zero or at most negative one.
1797 * If not, we mark the row as being redundant (assuming it hasn't
1798 * been detected as being obviously redundant in the mean time).
1800 struct isl_tab
*isl_tab_detect_redundant(struct isl_tab
*tab
)
1809 if (tab
->n_redundant
== tab
->n_row
)
1813 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
1814 struct isl_tab_var
*var
= isl_tab_var_from_row(tab
, i
);
1815 var
->marked
= !var
->frozen
&& var
->is_nonneg
;
1819 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
) {
1820 struct isl_tab_var
*var
= var_from_col(tab
, i
);
1821 var
->marked
= !var
->frozen
&& var
->is_nonneg
&&
1822 !min_is_manifestly_unbounded(tab
, var
);
1827 struct isl_tab_var
*var
;
1828 for (i
= tab
->n_redundant
; i
< tab
->n_row
; ++i
) {
1829 var
= isl_tab_var_from_row(tab
, i
);
1833 if (i
== tab
->n_row
) {
1834 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
) {
1835 var
= var_from_col(tab
, i
);
1839 if (i
== tab
->n_col
)
1844 if ((tab
->rational
? (sign_of_min(tab
, var
) >= 0)
1845 : !isl_tab_min_at_most_neg_one(tab
, var
)) &&
1847 isl_tab_mark_redundant(tab
, var
->index
);
1848 for (i
= tab
->n_dead
; i
< tab
->n_col
; ++i
) {
1849 var
= var_from_col(tab
, i
);
1852 if (!min_is_manifestly_unbounded(tab
, var
))
1862 int isl_tab_is_equality(struct isl_tab
*tab
, int con
)
1869 if (tab
->con
[con
].is_zero
)
1871 if (tab
->con
[con
].is_redundant
)
1873 if (!tab
->con
[con
].is_row
)
1874 return tab
->con
[con
].index
< tab
->n_dead
;
1876 row
= tab
->con
[con
].index
;
1879 return isl_int_is_zero(tab
->mat
->row
[row
][1]) &&
1880 isl_seq_first_non_zero(tab
->mat
->row
[row
] + 2 + tab
->n_dead
,
1881 tab
->n_col
- tab
->n_dead
) == -1;
1884 /* Return the minimial value of the affine expression "f" with denominator
1885 * "denom" in *opt, *opt_denom, assuming the tableau is not empty and
1886 * the expression cannot attain arbitrarily small values.
1887 * If opt_denom is NULL, then *opt is rounded up to the nearest integer.
1888 * The return value reflects the nature of the result (empty, unbounded,
1889 * minmimal value returned in *opt).
1891 enum isl_lp_result
isl_tab_min(struct isl_tab
*tab
,
1892 isl_int
*f
, isl_int denom
, isl_int
*opt
, isl_int
*opt_denom
,
1896 enum isl_lp_result res
= isl_lp_ok
;
1897 struct isl_tab_var
*var
;
1898 struct isl_tab_undo
*snap
;
1901 return isl_lp_empty
;
1903 snap
= isl_tab_snap(tab
);
1904 r
= isl_tab_add_row(tab
, f
);
1906 return isl_lp_error
;
1908 isl_int_mul(tab
->mat
->row
[var
->index
][0],
1909 tab
->mat
->row
[var
->index
][0], denom
);
1912 find_pivot(tab
, var
, var
, -1, &row
, &col
);
1913 if (row
== var
->index
) {
1914 res
= isl_lp_unbounded
;
1919 isl_tab_pivot(tab
, row
, col
);
1921 if (ISL_FL_ISSET(flags
, ISL_TAB_SAVE_DUAL
)) {
1924 isl_vec_free(tab
->dual
);
1925 tab
->dual
= isl_vec_alloc(tab
->mat
->ctx
, 1 + tab
->n_con
);
1927 return isl_lp_error
;
1928 isl_int_set(tab
->dual
->el
[0], tab
->mat
->row
[var
->index
][0]);
1929 for (i
= 0; i
< tab
->n_con
; ++i
) {
1931 if (tab
->con
[i
].is_row
) {
1932 isl_int_set_si(tab
->dual
->el
[1 + i
], 0);
1935 pos
= 2 + tab
->M
+ tab
->con
[i
].index
;
1936 if (tab
->con
[i
].negated
)
1937 isl_int_neg(tab
->dual
->el
[1 + i
],
1938 tab
->mat
->row
[var
->index
][pos
]);
1940 isl_int_set(tab
->dual
->el
[1 + i
],
1941 tab
->mat
->row
[var
->index
][pos
]);
1944 if (opt
&& res
== isl_lp_ok
) {
1946 isl_int_set(*opt
, tab
->mat
->row
[var
->index
][1]);
1947 isl_int_set(*opt_denom
, tab
->mat
->row
[var
->index
][0]);
1949 isl_int_cdiv_q(*opt
, tab
->mat
->row
[var
->index
][1],
1950 tab
->mat
->row
[var
->index
][0]);
1952 if (isl_tab_rollback(tab
, snap
) < 0)
1953 return isl_lp_error
;
1957 int isl_tab_is_redundant(struct isl_tab
*tab
, int con
)
1961 if (tab
->con
[con
].is_zero
)
1963 if (tab
->con
[con
].is_redundant
)
1965 return tab
->con
[con
].is_row
&& tab
->con
[con
].index
< tab
->n_redundant
;
1968 /* Take a snapshot of the tableau that can be restored by s call to
1971 struct isl_tab_undo
*isl_tab_snap(struct isl_tab
*tab
)
1979 /* Undo the operation performed by isl_tab_relax.
1981 static void unrelax(struct isl_tab
*tab
, struct isl_tab_var
*var
)
1983 unsigned off
= 2 + tab
->M
;
1985 if (!var
->is_row
&& !max_is_manifestly_unbounded(tab
, var
))
1986 to_row(tab
, var
, 1);
1989 isl_int_sub(tab
->mat
->row
[var
->index
][1],
1990 tab
->mat
->row
[var
->index
][1], tab
->mat
->row
[var
->index
][0]);
1994 for (i
= 0; i
< tab
->n_row
; ++i
) {
1995 if (isl_int_is_zero(tab
->mat
->row
[i
][off
+ var
->index
]))
1997 isl_int_add(tab
->mat
->row
[i
][1], tab
->mat
->row
[i
][1],
1998 tab
->mat
->row
[i
][off
+ var
->index
]);
2004 static void perform_undo_var(struct isl_tab
*tab
, struct isl_tab_undo
*undo
)
2006 struct isl_tab_var
*var
= var_from_index(tab
, undo
->u
.var_index
);
2007 switch(undo
->type
) {
2008 case isl_tab_undo_nonneg
:
2011 case isl_tab_undo_redundant
:
2012 var
->is_redundant
= 0;
2015 case isl_tab_undo_zero
:
2019 case isl_tab_undo_allocate
:
2020 if (undo
->u
.var_index
>= 0) {
2021 isl_assert(tab
->mat
->ctx
, !var
->is_row
, return);
2022 drop_col(tab
, var
->index
);
2026 if (!max_is_manifestly_unbounded(tab
, var
))
2027 to_row(tab
, var
, 1);
2028 else if (!min_is_manifestly_unbounded(tab
, var
))
2029 to_row(tab
, var
, -1);
2031 to_row(tab
, var
, 0);
2033 drop_row(tab
, var
->index
);
2035 case isl_tab_undo_relax
:
2041 /* Restore the tableau to the state where the basic variables
2042 * are those in "col_var".
2043 * We first construct a list of variables that are currently in
2044 * the basis, but shouldn't. Then we iterate over all variables
2045 * that should be in the basis and for each one that is currently
2046 * not in the basis, we exchange it with one of the elements of the
2047 * list constructed before.
2048 * We can always find an appropriate variable to pivot with because
2049 * the current basis is mapped to the old basis by a non-singular
2050 * matrix and so we can never end up with a zero row.
2052 static int restore_basis(struct isl_tab
*tab
, int *col_var
)
2056 int *extra
= NULL
; /* current columns that contain bad stuff */
2057 unsigned off
= 2 + tab
->M
;
2059 extra
= isl_alloc_array(tab
->mat
->ctx
, int, tab
->n_col
);
2062 for (i
= 0; i
< tab
->n_col
; ++i
) {
2063 for (j
= 0; j
< tab
->n_col
; ++j
)
2064 if (tab
->col_var
[i
] == col_var
[j
])
2068 extra
[n_extra
++] = i
;
2070 for (i
= 0; i
< tab
->n_col
&& n_extra
> 0; ++i
) {
2071 struct isl_tab_var
*var
;
2074 for (j
= 0; j
< tab
->n_col
; ++j
)
2075 if (col_var
[i
] == tab
->col_var
[j
])
2079 var
= var_from_index(tab
, col_var
[i
]);
2081 for (j
= 0; j
< n_extra
; ++j
)
2082 if (!isl_int_is_zero(tab
->mat
->row
[row
][off
+extra
[j
]]))
2084 isl_assert(tab
->mat
->ctx
, j
< n_extra
, goto error
);
2085 isl_tab_pivot(tab
, row
, extra
[j
]);
2086 extra
[j
] = extra
[--n_extra
];
2098 static int perform_undo(struct isl_tab
*tab
, struct isl_tab_undo
*undo
)
2100 switch (undo
->type
) {
2101 case isl_tab_undo_empty
:
2104 case isl_tab_undo_nonneg
:
2105 case isl_tab_undo_redundant
:
2106 case isl_tab_undo_zero
:
2107 case isl_tab_undo_allocate
:
2108 case isl_tab_undo_relax
:
2109 perform_undo_var(tab
, undo
);
2111 case isl_tab_undo_bset_eq
:
2112 isl_basic_set_free_equality(tab
->bset
, 1);
2114 case isl_tab_undo_bset_ineq
:
2115 isl_basic_set_free_inequality(tab
->bset
, 1);
2117 case isl_tab_undo_bset_div
:
2118 isl_basic_set_free_div(tab
->bset
, 1);
2120 tab
->samples
->n_col
--;
2122 case isl_tab_undo_saved_basis
:
2123 if (restore_basis(tab
, undo
->u
.col_var
) < 0)
2126 case isl_tab_undo_drop_sample
:
2130 isl_assert(tab
->mat
->ctx
, 0, return -1);
2135 /* Return the tableau to the state it was in when the snapshot "snap"
2138 int isl_tab_rollback(struct isl_tab
*tab
, struct isl_tab_undo
*snap
)
2140 struct isl_tab_undo
*undo
, *next
;
2146 for (undo
= tab
->top
; undo
&& undo
!= &tab
->bottom
; undo
= next
) {
2150 if (perform_undo(tab
, undo
) < 0) {
2164 /* The given row "row" represents an inequality violated by all
2165 * points in the tableau. Check for some special cases of such
2166 * separating constraints.
2167 * In particular, if the row has been reduced to the constant -1,
2168 * then we know the inequality is adjacent (but opposite) to
2169 * an equality in the tableau.
2170 * If the row has been reduced to r = -1 -r', with r' an inequality
2171 * of the tableau, then the inequality is adjacent (but opposite)
2172 * to the inequality r'.
2174 static enum isl_ineq_type
separation_type(struct isl_tab
*tab
, unsigned row
)
2177 unsigned off
= 2 + tab
->M
;
2180 return isl_ineq_separate
;
2182 if (!isl_int_is_one(tab
->mat
->row
[row
][0]))
2183 return isl_ineq_separate
;
2184 if (!isl_int_is_negone(tab
->mat
->row
[row
][1]))
2185 return isl_ineq_separate
;
2187 pos
= isl_seq_first_non_zero(tab
->mat
->row
[row
] + off
+ tab
->n_dead
,
2188 tab
->n_col
- tab
->n_dead
);
2190 return isl_ineq_adj_eq
;
2192 if (!isl_int_is_negone(tab
->mat
->row
[row
][off
+ tab
->n_dead
+ pos
]))
2193 return isl_ineq_separate
;
2195 pos
= isl_seq_first_non_zero(
2196 tab
->mat
->row
[row
] + off
+ tab
->n_dead
+ pos
+ 1,
2197 tab
->n_col
- tab
->n_dead
- pos
- 1);
2199 return pos
== -1 ? isl_ineq_adj_ineq
: isl_ineq_separate
;
2202 /* Check the effect of inequality "ineq" on the tableau "tab".
2204 * isl_ineq_redundant: satisfied by all points in the tableau
2205 * isl_ineq_separate: satisfied by no point in the tableau
2206 * isl_ineq_cut: satisfied by some by not all points
2207 * isl_ineq_adj_eq: adjacent to an equality
2208 * isl_ineq_adj_ineq: adjacent to an inequality.
2210 enum isl_ineq_type
isl_tab_ineq_type(struct isl_tab
*tab
, isl_int
*ineq
)
2212 enum isl_ineq_type type
= isl_ineq_error
;
2213 struct isl_tab_undo
*snap
= NULL
;
2218 return isl_ineq_error
;
2220 if (isl_tab_extend_cons(tab
, 1) < 0)
2221 return isl_ineq_error
;
2223 snap
= isl_tab_snap(tab
);
2225 con
= isl_tab_add_row(tab
, ineq
);
2229 row
= tab
->con
[con
].index
;
2230 if (isl_tab_row_is_redundant(tab
, row
))
2231 type
= isl_ineq_redundant
;
2232 else if (isl_int_is_neg(tab
->mat
->row
[row
][1]) &&
2234 isl_int_abs_ge(tab
->mat
->row
[row
][1],
2235 tab
->mat
->row
[row
][0]))) {
2236 if (at_least_zero(tab
, &tab
->con
[con
]))
2237 type
= isl_ineq_cut
;
2239 type
= separation_type(tab
, row
);
2240 } else if (tab
->rational
? (sign_of_min(tab
, &tab
->con
[con
]) < 0)
2241 : isl_tab_min_at_most_neg_one(tab
, &tab
->con
[con
]))
2242 type
= isl_ineq_cut
;
2244 type
= isl_ineq_redundant
;
2246 if (isl_tab_rollback(tab
, snap
))
2247 return isl_ineq_error
;
2250 isl_tab_rollback(tab
, snap
);
2251 return isl_ineq_error
;
2254 void isl_tab_dump(struct isl_tab
*tab
, FILE *out
, int indent
)
2260 fprintf(out
, "%*snull tab\n", indent
, "");
2263 fprintf(out
, "%*sn_redundant: %d, n_dead: %d", indent
, "",
2264 tab
->n_redundant
, tab
->n_dead
);
2266 fprintf(out
, ", rational");
2268 fprintf(out
, ", empty");
2270 fprintf(out
, "%*s[", indent
, "");
2271 for (i
= 0; i
< tab
->n_var
; ++i
) {
2273 fprintf(out
, (i
== tab
->n_param
||
2274 i
== tab
->n_var
- tab
->n_div
) ? "; "
2276 fprintf(out
, "%c%d%s", tab
->var
[i
].is_row
? 'r' : 'c',
2278 tab
->var
[i
].is_zero
? " [=0]" :
2279 tab
->var
[i
].is_redundant
? " [R]" : "");
2281 fprintf(out
, "]\n");
2282 fprintf(out
, "%*s[", indent
, "");
2283 for (i
= 0; i
< tab
->n_con
; ++i
) {
2286 fprintf(out
, "%c%d%s", tab
->con
[i
].is_row
? 'r' : 'c',
2288 tab
->con
[i
].is_zero
? " [=0]" :
2289 tab
->con
[i
].is_redundant
? " [R]" : "");
2291 fprintf(out
, "]\n");
2292 fprintf(out
, "%*s[", indent
, "");
2293 for (i
= 0; i
< tab
->n_row
; ++i
) {
2294 const char *sign
= "";
2297 if (tab
->row_sign
) {
2298 if (tab
->row_sign
[i
] == isl_tab_row_unknown
)
2300 else if (tab
->row_sign
[i
] == isl_tab_row_neg
)
2302 else if (tab
->row_sign
[i
] == isl_tab_row_pos
)
2307 fprintf(out
, "r%d: %d%s%s", i
, tab
->row_var
[i
],
2308 isl_tab_var_from_row(tab
, i
)->is_nonneg
? " [>=0]" : "", sign
);
2310 fprintf(out
, "]\n");
2311 fprintf(out
, "%*s[", indent
, "");
2312 for (i
= 0; i
< tab
->n_col
; ++i
) {
2315 fprintf(out
, "c%d: %d%s", i
, tab
->col_var
[i
],
2316 var_from_col(tab
, i
)->is_nonneg
? " [>=0]" : "");
2318 fprintf(out
, "]\n");
2319 r
= tab
->mat
->n_row
;
2320 tab
->mat
->n_row
= tab
->n_row
;
2321 c
= tab
->mat
->n_col
;
2322 tab
->mat
->n_col
= 2 + tab
->M
+ tab
->n_col
;
2323 isl_mat_dump(tab
->mat
, out
, indent
);
2324 tab
->mat
->n_row
= r
;
2325 tab
->mat
->n_col
= c
;
2327 isl_basic_set_dump(tab
->bset
, out
, indent
);