22#define dbgCompParmMore 0
25 if (dbgCompParmMore) { \
26 printf(" -- begin "); \
32 if (dbgCompParmMore) { \
45 Matrix *U, *Q, *H, *H2, *K = NULL;
57 printf(
"rank = %d\n", rk);
77 printf(
"-- Int. Kernel -- \n");
125 for (i = 0; i < rk; i++) {
171 Matrix *Hm, *H = NULL, *U, *Q, *M = NULL, *C = NULL, *Hi;
216 for (i = 0; i < rk; i++) {
233 for (i = rk; i < Eqs->
NbColumns - 2; i++) {
262 unsigned int r = Eqs->
NbRows;
263 Matrix *A = NULL, *B = NULL, *I = NULL, *Lb = NULL, *sol = NULL;
268 printf(
"Computing validity lattice induced by the %d first variables of:",
307 for (i = 0; i < b; i++) {
325 unsigned int *elimParms,
Matrix **newM) {
326 unsigned int i, j, k;
327 if (elimParms[0] == 0) {
331 if ((*newM) == NULL) {
336 for (i = 0; i < M->
NbRows; i++) {
339 Vector_Copy(&(M->
p[i][1]), &((*newM)->p[i][1]), nbVars);
340 for (j = 0; j < M->
NbColumns - 2 - nbVars; j++) {
341 if (j != elimParms[k + 1]) {
343 M->
p[i][j + nbVars + 1]);
375 unsigned int **elimVars,
376 unsigned int **elimParms,
int maxRays) {
378 Matrix *A = NULL, *B = NULL;
380 unsigned int nbVars = (*M)->
NbColumns - (*C)->NbColumns;
381 unsigned int nbParms;
386 unsigned int *permutation;
387 Matrix *permutedEqs = NULL, *permutedIneqs = NULL;
392 if ((*M)->NbColumns == 0)
395 if (elimParms[0] != 0) {
403 printf(
"After false parameter elimination: \n");
408 nbParms = (*C)->NbColumns - 2;
413 nbElimVars = (*Eqs)->NbRows;
415 if ((*Eqs)->NbRows == 0) {
423 printf(
"Permuting the vars/parms this way: [ ");
424 for (i = 0; i < (*Eqs)->NbColumns - 2; i++) {
425 printf(
"%d ", permutation[i]);
434 printf(
"Validity lattice: ");
447 printf(
"After compression: ");
453 printf(
"After elimination of the variables: ");
460 permutedIneqs->NbColumns - nbElimVars);
461 for (i = 0; i < permutedIneqs->NbRows; i++) {
463 for (j = 0; j < nbParms; j++) {
465 permutedIneqs->p[i][j + nbElimVars + 1]);
467 for (j = 0; j < permutedIneqs->NbColumns - nbParms - 2 - nbElimVars; j++) {
469 permutedIneqs->p[i][nbElimVars + nbParms + j + 1]);
472 permutedIneqs->p[i][permutedIneqs->NbColumns - 1]);
486 Matrix *H, *Q, *U, *linLat = NULL;
490 if (k == lat->
NbRows - 1) {
491 if (*subLat == NULL) {
499 assert(k < lat->NbRows - 1);
513 if (*subLat == NULL) {
519 for (i = 0; i < k; i++) {
537 Value *periods = (Value *)malloc(
sizeof(Value) * M->
NbColumns);
543 for (i = 0; i < M->
NbRows; i++) {
588 for (i = 0; i < nbEqs; i++) {
634 int renderSpace,
unsigned int **elimParms) {
635 int i, j, k, nbEqsParms = 0;
636 int nbEqsM, nbEqsCtxt, allZeros, nbTautoM = 0, nbTautoCtxt = 0;
645 for (i = 0; i < M->
NbRows; i++) {
658 for (i = 0; i < Ctxt->
NbRows; i++) {
667 nbEqsParms = nbEqsM + nbEqsCtxt;
670 if (nbEqsParms + nbTautoM + nbTautoCtxt == 0) {
671 (*elimParms) = (
unsigned int *)malloc(
sizeof(
int));
673 if (renderSpace == 0) {
685 for (i = 0; i < Ctxt->
NbRows; i++) {
694 for (i = 0; i < M->
NbRows; i++) {
697 if (j >= nbVars + 1) {
699 Vector_Copy(M->
p[i] + nbVars + 1, EqsMTmp->
p[k] + nbVars + 1,
713 (*elimParms) = (
unsigned int *)malloc((Eqs->
NbRows + 1) *
sizeof(int));
716 for (i = 0; i < Eqs->
NbRows; i++) {
723 printf(
"Contradiction in %dth row of Eqs: ", k);
732 (*elimParms) = (
unsigned int *)malloc(
sizeof(
int));
734 if (renderSpace == 1) {
745 (*elimParms)[(*elimParms[0])] = k;
746 for (j = 0; j < Eqs->
NbRows; j++) {
752 for (j = 0; j < Ctxt->
NbRows; j++) {
757 for (j = 0; j < M->
NbRows; j++) {
772 if (!realloc((*elimParms), ((*elimParms)[0] + 1) *
sizeof(
int))) {
773 fprintf(stderr,
"Constraints_Remove_parm_eqs > cannot realloc()");
782 for (i = 0; i < M->
NbRows; i++) {
794 for (i = 0; i < Ctxt->
NbRows; i++) {
803 if (renderSpace == 0) {
806 for (i = 0; i < Eqs->
NbRows; i++) {
815 for (i = 0; i < Eqs->
NbRows; i++) {
837 unsigned int **elimParms,
int maxRays) {
882 Matrix **validityLattice) {
884 Matrix *permutedEqs, *permutedIneqs;
889 unsigned int *permutation, *permutationInv;
906 printf(
"Permuting the vars/parms this way: [ ");
908 printf(
"%d ", permutation[i]);
916 fprintf(stderr,
"full_dimensionize > parameters compression failed.\n");
923 printf(
"Whole validity lattice: ");
935 printf(
"After compression: ");
940 fprintf(stderr,
"full_dimensionize > variable elimination failed.\n");
946 printf(
"After elimination of the variables: ");
954 for (i = 0; i < permutedIneqs->
NbRows; i++) {
956 for (j = 0; j < nbParms; j++)
958 permutedIneqs->
p[i][j + nbElimVars + 1]);
959 for (j = 0; j < permutedIneqs->
NbColumns - nbParms - 2 - nbElimVars; j++)
961 permutedIneqs->
p[i][nbElimVars + nbParms + j + 1]);
963 permutedIneqs->
p[i][permutedIneqs->
NbColumns - 1]);
968 *validityLattice =
Matrix_Alloc(nbParms + 1, nbParms + 1);
969 for (i = 0; i < nbParms; i++) {
970 for (j = 0; j < nbParms; j++)
975 for (j = 0; j < nbParms; j++)
986#undef dbgCompParmMore
Matrix * Matrix_Copy(Matrix const *Src)
#define value_pdivision(ref, val1, val2)
#define value_notzero_p(val)
#define value_divexact(ref, val1, val2)
#define value_gcd(ref, val1, val2)
#define value_pmodulus(ref, val1, val2)
#define value_lcm(ref, val1, val2)
#define value_zero_p(val)
#define value_assign(v1, v2)
#define value_set_si(val, i)
#define value_cmp_si(val, n)
void Equalities_integerSolution(Matrix *Eqs, Matrix **I)
Given a system of equalities, looks if it has an integer solution in the combined space,...
Matrix * compress_parms(Matrix *E, int nbParms)
Given a parameterized constraints matrix with m equalities, computes the compression matrix G such th...
void Equalities_intModBasis(Matrix *B, Matrix *C, Matrix *d, Matrix **imb)
Given an integer matrix B with m rows and integer m-vectors C and d, computes the basis of the intege...
void Constraints_fullDimensionize(Matrix **M, Matrix **C, Matrix **VL, Matrix **Eqs, Matrix **ParmEqs, unsigned int **elimVars, unsigned int **elimParms, int maxRays)
Eliminates all the equalities in a set of constraints and returns the set of constraints defining a f...
#define dbgCompParm
debug flags (2 levels)
void Constraints_removeElimCols(Matrix *M, unsigned int nbVars, unsigned int *elimParms, Matrix **newM)
Eliminate the columns corresponding to a list of eliminated parameters.
Matrix * Constraints_Remove_parm_eqs(Matrix **M1, Matrix **Ctxt1, int renderSpace, unsigned int **elimParms)
Removes the equalities that involve only parameters, by eliminating some parameters in the polyhedron...
Matrix * affine_periods(Matrix *M, Matrix *d)
Computes the overall period of the variables I for (MI) mod |d|, where M is a matrix and |d| a vector...
static void linearInter(Matrix *A, Matrix *B, Matrix **I, Matrix **Lb)
Computes the intersection of two linear lattices, whose base vectors are respectively represented in ...
Matrix * int_mod_basis(Matrix *B, Matrix *C, Matrix *d)
kept here for backwards compatiblity.
void Lattice_extractSubLattice(Matrix *lat, unsigned int k, Matrix **subLat)
Given a matrix that defines a full-dimensional affine lattice, returns the affine sub-lattice spanned...
Matrix * int_ker(Matrix *M)
Given a full-row-rank nxm matrix M made of m row-vectors), computes the basis K (made of n-m column-v...
void Equalities_validityLattice(Matrix *Eqs, int a, Matrix **vl)
Computes the validity lattice of a set of equalities.
Polyhedron * Polyhedron_Remove_parm_eqs(Polyhedron **P, Polyhedron **C, int renderSpace, unsigned int **elimParms, int maxRays)
Removes equalities involving only parameters, but starting from a Polyhedron and its context.
Matrix * full_dimensionize(Matrix const *M, int nbParms, Matrix **validityLattice)
Given a matrix with m parameterized equations, compress the nb_parms parameters and n-m variables so ...
#define Constraints_removeParmEqs(a, b, c, d)
void Matrix_Product(Matrix *Mat1, Matrix *Mat2, Matrix *Mat3)
Matrix * Matrix_Alloc(unsigned NbRows, unsigned NbColumns)
void right_hermite(Matrix *A, Matrix **Hp, Matrix **Up, Matrix **Qp)
void left_hermite(Matrix *A, Matrix **Hp, Matrix **Qp, Matrix **Up)
int MatInverse(Matrix *Mat, Matrix *MatInv)
void Matrix_Free(Matrix *Mat)
void split_constraints(Matrix const *M, Matrix **Eqs, Matrix **Ineqs)
splits a matrix of constraints M into a matrix of equalities Eqs and a matrix of inequalities Ineqs a...
void Matrix_subMatrix(Matrix *M, unsigned int sr, unsigned int sc, unsigned int er, unsigned int ec, Matrix **sub)
returns a contiguous submatrix of a matrix.
void mpolyhedron_compress_last_vars(Matrix *M, Matrix *compression)
compress the last vars/pars of the polyhedron M expressed as a polylib matrix
Matrix * Identity_Matrix(unsigned int dim)
unsigned int mpolyhedron_eliminate_first_variables(Matrix *Eqs, Matrix *Ineqs)
use a set of m equalities Eqs to eliminate m variables in the polyhedron Ineqs represented as a matri...
void eliminate_var_with_constr(Matrix *Eliminator, unsigned int eliminator_row, Matrix *Victim, unsigned int victim_row, unsigned int var_to_elim)
use an eliminator row to eliminate a variable in a victim row (without changing the sign of the victi...
void Matrix_clone(Matrix *M, Matrix **Cl)
Cloning function.
void Matrix_copySubMatrix(Matrix *M1, unsigned int sr1, unsigned int sc1, unsigned int nbR, unsigned int nbC, Matrix *M2, unsigned int sr2, unsigned int sc2)
Copies a contiguous submatrix of M1 into M2, at the indicated position.
void Matrix_oppose(Matrix *M)
transforms a matrix M into -M
void Matrix_identity(unsigned int dim, Matrix **I)
returns the dim-dimensional identity matrix.
#define show_matrix(M)
Polylib matrix addons Mainly, deals with polyhedra represented in implicit form (set of constraints).
#define ensureMatrix(M, r, c)
Allocates a matrix if it is null, or else asserts that it has at least a certain size.
#define Constraints_compressLastVars(a, b)
#define Constraints_eliminateFirstVars(a, b)
void Constraints_permute(Matrix *C, unsigned int *perm, Matrix **Cp)
permutes the variables of the constraints of a polyhedron
Matrix * mpolyhedron_permute(Matrix *polyh, unsigned int *permutation)
permutes the variables of the constraints of a polyhedron
unsigned int * find_a_permutation(Matrix *Eqs, unsigned int nb_parms)
finds a valid permutation : for a set of m equations, find m variables that will be put at the beginn...
void Polyhedron_Free(Polyhedron *Pol)
Matrix * Polyhedron2Constraints(Polyhedron *Pol)
Polyhedron * Constraints2Polyhedron(Matrix *Constraints, unsigned NbMaxRays)
Given a matrix of constraints ('Constraints'), construct and return a polyhedron.
void Vector_Set(Value *p, int n, unsigned length)
int Vector_IsZero(Value *v, unsigned length)
void Vector_Copy(Value *p1, Value *p2, unsigned length)
int First_Non_Zero(Value *p, unsigned length)