-/* Tighten (decrease) the constant terms of the inequalities based
- * on the equalities, without removing any integer points.
- * For example, if there is an equality
- *
- * i = 3 * j
- *
- * and an inequality
- *
- * i >= 1
- *
- * then we want to replace the inequality by
- *
- * i >= 3
- *
- * We do this by computing a variable compression and translating
- * the constraints to the compressed space.
- * If any constraint has coefficients (except the contant term)
- * with a common factor "f", then we can replace the constant term "c"
- * by
- *
- * f * floor(c/f)
- *
- * That is, we add
- *
- * f * floor(c/f) - c = -fract(c/f)
- *
- * and we can add the same value to the original constraint.
- *
- * In the example, the compressed space only contains "j",
- * and the inequality translates to
- *
- * 3 * j - 1 >= 0
- *
- * We add -fract(-1/3) = -2 to the original constraint to obtain
- *
- * i - 3 >= 0
- */
-static struct isl_basic_set *normalize_constraints_in_compressed_space(
- struct isl_basic_set *bset)
-{
- int i;
- unsigned total;
- struct isl_mat *B, *C;
- isl_int gcd;
-
- if (!bset)
- return NULL;
-
- if (ISL_F_ISSET(bset, ISL_BASIC_SET_RATIONAL))
- return bset;
-
- if (!bset->n_ineq)
- return bset;
-
- bset = isl_basic_set_cow(bset);
- if (!bset)
- return NULL;
-
- total = isl_basic_set_total_dim(bset);
- B = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, bset->n_eq, 0, 1 + total);
- C = isl_mat_variable_compression(B, NULL);
- if (!C)
- return bset;
- if (C->n_col == 0) {
- isl_mat_free(C);
- return isl_basic_set_set_to_empty(bset);
- }
- B = isl_mat_sub_alloc6(bset->ctx, bset->ineq,
- 0, bset->n_ineq, 0, 1 + total);
- C = isl_mat_product(B, C);
- if (!C)
- return bset;
-
- isl_int_init(gcd);
- for (i = 0; i < bset->n_ineq; ++i) {
- isl_seq_gcd(C->row[i] + 1, C->n_col - 1, &gcd);
- if (isl_int_is_one(gcd))
- continue;
- isl_int_fdiv_r(C->row[i][0], C->row[i][0], gcd);
- isl_int_sub(bset->ineq[i][0], bset->ineq[i][0], C->row[i][0]);
- }
- isl_int_clear(gcd);
-
- isl_mat_free(C);
-
- return bset;
-}
-