18 for (temp = Head; temp != NULL; temp = temp->
next)
30 while (Head != NULL) {
62 fp = fopen(
"_debug",
"a");
63 fprintf(fp,
"\nEntered SAMEAFFINEPART \n");
67 for (i = 0; i < A->
NbRows; i++)
84 fp = fopen(
"_debug",
"a");
85 fprintf(fp,
"\nEntered NULLATTICE \n");
90 for (i = 0; i < dimension; i++)
91 for (j = 0; j < dimension; j++)
106 fp = fopen(
"_debug",
"a");
107 fprintf(fp,
"\nEntered ISNULLATTICE \n");
111 for (i = 0; i < A->
NbRows - 1; i++)
133 fp = fopen(
"_debug",
"a");
134 fprintf(fp,
"\nEntered ISLINEAR \n");
138 for (i = 0; i < A->
NbRows - 1; i++)
165 fp = fopen(
"_debug",
"a");
166 fprintf(fp,
"\nEntered AFFINEHERMITE \n");
212 fp = fopen(
"_debug",
"a");
213 fprintf(fp,
"\nEntered AFFINESMITH \n");
244 for (i = 0; i < U[0]->
NbRows - 1; i++) {
246 for (j = 0; j < U[0]->
NbColumns - 1; j++) {
252 for (i = 0; i < U[0]->
NbRows - 1; i++)
254 for (i = 0; i < Diag[0]->
NbRows - 1; i++) {
257 value_modulus(rem, Diag[0]->p[i][Diag[0]->NbColumns - 1], Diag[0]->p[i][i]);
259 fprintf(stdout,
" pourcent ");
261 fprintf(stdout,
" quotient ");
263 fprintf(stdout,
" \n");
270 fprintf(stdout,
"apres pourcent ");
272 fprintf(stdout,
" quotient ");
274 fprintf(stdout,
" \n");
275 value_assign(Diag[0]->p[i][Diag[0]->NbColumns - 1], rem);
303 fp = fopen(
"_debug",
"a");
304 fprintf(fp,
"\nEntered HOMOGENISE \n");
309 if (Forward ==
True) {
331 fp = fopen(
"_debug",
"a");
332 fprintf(fp,
"\nEntered LATTICE INCLUDES \n");
363 fp = fopen(
"_debug",
"a");
364 fprintf(fp,
"\nEntered SAME LATTICE \n");
371 for (i = 0; i < A->
NbRows; i++)
399 if (dimension <= A->NbRows) {
400 for (i = 0; i < dimension; i++)
401 for (j = 0; j < dimension; j++)
405 for (i = 0; i < A->
NbRows; i++)
406 for (j = 0; j < A->
NbRows; j++)
409 for (i = A->
NbRows; i < dimension; i++)
410 for (j = 0; j < dimension; j++) {
414 for (i = A->
NbRows; i < dimension; i++)
428 for (i = 0; i < A->
NbRows - 1; i++)
462 Lattice *result = NULL, *U = NULL;
463 Lattice *A = NULL, *B = NULL, *H = NULL;
469 fp = fopen(
"_debug",
"a");
470 fprintf(fp,
"\nEntered LATTICEINTERSECTION \n");
475 fprintf(stderr,
"\nIn LatticeIntersection : The Input Matrix X is a not a "
476 "well defined Lattice\n");
481 fprintf(stderr,
"\nIn LatticeIntersection : The Input Matrix Y is a not a "
482 "well defined Lattice\n");
487 fprintf(stderr,
"\nIn LatticeIntersection : the input lattices X and Y are "
488 "of incompatible dimensions\n");
526 for (i = 0; i < result->
NbRows - 1; i++)
527 for (j = 0; j < result->
NbColumns - 1; j++)
530 for (i = 0; i < result->
NbRows - 1; i++)
532 for (i = 0; i < result->
NbColumns - 1; i++)
563 fp = fopen(
"_debug",
"a");
564 fprintf(fp,
"\nEntered MAKEDIOEQFORINTER \n");
570 for (i = 0; i < Dio->
NbRows; i++)
574 for (i = 0; i < A->
NbRows - 1; i++) {
578 for (i = 0; i < A->
NbRows - 1; i++)
579 for (j = 0; j < A->
NbRows - 1; j++) {
663 Lattice *B1 = NULL, *B2 = NULL, *newB1 = NULL, *newB2 = NULL,
664 *Intersection = NULL;
665 Matrix *U = NULL, *M1 = NULL, *M2 = NULL, *M1Inverse = NULL,
667 Matrix *Vinv, *V, *temp, *DiagMatrix;
675 fprintf(stderr,
"\nIn Lattice2LatticeUnion : the input lattices X and Y do "
676 "not have any common part\n");
691 Smith(MtProduct, &U, &Vinv, &DiagMatrix);
703 for (i = 0; i < DiagMatrix->
NbRows; i++)
709 for (i = 0; i < newB1->NbRows - 1; i++)
711 Intersection->p[i][X->
NbRows - 1]);
810 fp = fopen(
"_debug",
"a");
811 fprintf(fp,
"\nEntered LATTICEDIFFERENCE \n");
816 fprintf(stderr,
"\nIn LatticeDifference : The Input Matrix A is not a "
817 "proper Lattice \n");
822 fprintf(stderr,
"\nIn LatticeDifference : The Input Matrix B is not a "
823 "proper Lattice \n");
829 "\nIn Lattice Difference : The Input Lattices A and B have ");
830 fprintf(stderr,
"incompatible dimensions \n");
869 tempHead->next = NULL;
897 for (i = 0; i < C->
NbRows; i++)
898 AddLattice(Head, B1, B2, VALUE_TO_INT(C->
p[i][i]), i);
917 int NumofTimes,
int Colnumber) {
925 while (tail->
next != NULL)
929 for (temp = Head; temp != NULL; temp = temp->
next) {
930 for (i = 1; i < NumofTimes; i++) {
934 for (j = 0; j < B2->
NbRows; j++) {
937 B1->
p[j][Colnumber]);
983 Matrix *temp, *temp1, *tempinv, *Newmat;
984 Matrix *vert, *rays, *result;
987 int noofvertices = 0, noofrays = 0;
988 int vercount, raycount;
993 fp = fopen(
"_debug",
"a");
994 fprintf(fp,
"\nEntered FINDHERMITEBASISOFDOMAIN \n");
1012 for (i = 0; i < A->
NbRays; i++)
1024 for (i = 0; i < A->
NbRays; i++) {
1039 for (i = 0; i < vert->
NbRows; i++) {
1041 for (j = 0; j < vert->
NbColumns - 1; j++)
1051 for (i = 1; i < temp->
NbRows; i++)
1060 for (i = 0; i < vert->
NbRows; i++)
1064 for (; i < result->
NbRows; i++)
1085 for (i = 0; i < rank; i++)
1088 for (i = 0; i < rank; i++)
1093 for (j = 1; j < Image->
Dimension + 2; j++)
1099 for (i = 0; i < Newmat->
NbColumns - 1; i++)
1125 fp = fopen(
"_debug",
"a");
1126 fprintf(fp,
"\nEntered LATTICEIMAGE \n");
1169 fp = fopen(
"_debug",
"a");
1170 fprintf(fp,
"\nEntered LATTICEPREIMAGE \n");
1176 fprintf(stderr,
"\nIn LatticePreimage: Incompatible types of Lattice and "
1187 for (i = 0; i < G->
NbRows - 1; i++)
1191 for (i = 0; i < G->
NbRows - 1; i++)
1192 for (j = 0; j < L->
NbColumns - 1; j++) {
1197 for (i = 0; i < Dio->
NbRows - 1; i++) {
1202 for (i = 0; i < Dio->
NbColumns - 1; i++)
1212 for (i = 0; i < Result->
NbRows - 1; i++)
1213 for (j = 0; j < Result->
NbColumns - 1; j++)
1216 for (i = 0; i < Result->
NbRows - 1; i++)
1220 for (i = 0; i < Result->
NbColumns - 1; i++)
1240 fp = fopen(
"_debug",
"a");
1241 fprintf(fp,
"\nEntered ISLATTICE \n");
1248 if (
m->NbRows !=
m->NbColumns)
1251 for (i = 0; i <
m->NbColumns - 1; i++)
1274 for (i = 0; i < h->
NbRows; i++)
1309 Value cnt, aux, k, fac, num, tmp, foobar;
1311 if ((*InputList == NULL) || (InputList[0]->next == NULL))
1322 width = InputList[0]->
M->
NbRows - 1;
1323 allfac =
allfactors(VALUE_TO_INT(InputList[0]->M->p[dim][dim]));
1325 for (temp = InputList[0]; temp != NULL; temp = temp->
next)
1327 for (i = 0; i < allfac.
count; i++) {
1333 if (i == allfac.
count) {
1343 for (; i < allfac.
count; i++) {
1347 if (*InputList == NULL) {
1362 for (temp = *InputList; temp != NULL; temp = temp->
next) {
1367 if (
value_ge(fac, (*InputList)->M->p[dim][dim])) {
1376 if (Present ==
True) {
1378 if (*ResultList == NULL)
1381 for (temp = *ResultList; temp->
next != NULL; temp = temp->
next)
1396 temp = InputList[0];
1397 while (temp != NULL) {
1398 if (
value_eq(temp->
M->
p[width][width], tmp)) {
1399 if (temp == InputList[0]) {
1401 temp = InputList[0] = temp->
next;
1446 for (i = 0; i < L1[0]->
NbRows - 1; i++)
1447 for (j = 0; j <= i; j++) {
1448 if (
value_gt(L1[0]->p[i][j], L2[0]->p[i][j]))
1450 if (
value_lt(L1[0]->p[i][j], L2[0]->p[i][j]))
1468 for (temp = Head; temp != NULL; temp = temp->
next)
1474 for (temp = Head; temp != NULL; temp = temp->
next)
1475 Latlist[cnt++] = temp->
M;
1480 for (temp = Head; temp != NULL; temp = temp->
next)
1481 temp->
M = Latlist[cnt++];
1501 for (i = 0; i < L1[0]->
NbRows; i++) {
1502 if (
value_gt(L1[0]->p[i][L1[0]->NbColumns - 1],
1503 L2[0]->p[i][L1[0]->NbColumns - 1]))
1506 if (
value_lt(L1[0]->p[i][L1[0]->NbColumns - 1],
1507 L2[0]->p[i][L1[0]->NbColumns - 1]))
1524 for (tmp = List; tmp != NULL; tmp = tmp->
next)
1530 for (tmp = List; tmp != NULL; tmp = tmp->
next)
1531 LatList[cnt++] = tmp->
M;
1536 for (tmp = List; tmp != NULL; tmp = tmp->
next)
1537 tmp->
M = LatList[cnt++];
1545 if ((A == NULL) || (B == NULL))
1548 for (i = 0; i < A->
M->
NbRows - 1; i++)
1569 if (curlist == NULL)
1572 if (curlist->
next == NULL) {
1573 curlist->
next = newlist[0];
1574 newlist[0] = curlist;
1579 for (i = 0; i < curlist->
M->
NbRows - 1; i++) {
1584 for (temp = curlist; temp != NULL; temp = temp->
next) {
1594 while (curr != NULL) {
1598 chng =
Simplify(&curlist, newlist, i);
1599 if (nextlist == NULL)
1603 for (tmp = nextlist; tmp->
next; tmp = tmp->
next)
1605 tmp->
next = curlist;
1607 change = (
Bool)(change | chng);
1617 for (temp = curlist; temp != NULL; temp = temp->
next) {
1624 if (curlist == NULL)
1627 if (*newlist == NULL)
1628 *newlist = nextlist;
1630 for (curr = *newlist; curr->
next != NULL; curr = curr->
next)
1632 curr->
next = nextlist;
1641 if ((A == NULL) || (B == NULL))
1643 for (i = 0; i < A->
M->
NbRows - 1; i++)
1644 for (j = 0; j <= i; j++)
1661 while (change ==
True) {
1666 while (curr != NULL) {
1671 change = (
Bool)(change | chng);
1699 int *list, *newlist;
1703 list = (
int *)malloc(
sizeof(
int));
1708 if ((tmp % i) == 0) {
1709 if (noofelmts == 0) {
1710 list = (
int *)malloc(
sizeof(
int));
1714 newlist = (
int *)malloc(
sizeof(
int) * 2 * noofelmts + 1);
1715 for (j = 0; j < noofelmts; j++)
1716 newlist[j] = list[j];
1718 for (j = 0; j < noofelmts; j++)
1719 newlist[j + noofelmts + 1] = i * list[j];
1722 noofelmts = 2 * noofelmts + 1;
1729 if ((tmp != 0) && (tmp != num)) {
1730 newlist = (
int *)malloc(
sizeof(
int) * 2 * noofelmts + 1);
1731 for (j = 0; j < noofelmts; j++)
1732 newlist[j] = list[j];
1734 for (j = 0; j < noofelmts; j++)
1735 newlist[j + noofelmts + 1] = tmp * list[j];
1738 noofelmts = 2 * noofelmts + 1;
1740 qsort(list, noofelmts,
sizeof(
int),
intcompare);
1742 for (i = 1; i < noofelmts; i++)
1743 if (list[i] != list[i - 1])
1744 list[count++] = list[i];
1745 if (list[count - 1] == num)
1748 result.
fac = (
int *)malloc(
sizeof(
int) * count);
1749 result.
count = count;
1750 for (i = 0; i < count; i++)
1751 result.
fac[i] = list[i];
Lattice * EmptyLattice(int dimension)
LatticeUnion * LatticeUnion_Alloc(void)
Lattice * ExtractLinearPart(Lattice *A)
static void LinearPartSort(LatticeUnion *Head)
Bool IsLattice(Matrix *m)
static Matrix * MakeDioEqforInter(Matrix *A, Matrix *B)
static Bool Simplify(LatticeUnion **InputList, LatticeUnion **ResultList, int dim)
static void AddLattice(LatticeUnion *, Matrix *, Matrix *, int, int)
void AffineHermite(Lattice *A, Lattice **H, Matrix **U)
LatticeUnion * LatticeDifference(Lattice *A, Lattice *B)
Method :
Bool isLinear(Lattice *A)
static factor allfactors(int num)
Bool sameAffinepart(Lattice *A, Lattice *B)
static int AffinePartCompare(const void *A, const void *B)
Lattice * Homogenise(Lattice *A, Bool Forward)
Bool isEmptyLattice(Lattice *A)
static Bool SameLinearPart(LatticeUnion *A, LatticeUnion *B)
Lattice * ChangeLatticeDimension(Lattice *A, int dimension)
LatticeUnion * Lattice2LatticeUnion(Lattice *X, Lattice *Y)
static Bool AffinePartSimplify(LatticeUnion *curlist, LatticeUnion **newlist)
Lattice * LatticeIntersection(Lattice *X, Lattice *Y)
Bool isfulldim(Matrix *m)
static Bool AlmostSameAffinePart(LatticeUnion *A, LatticeUnion *B)
static void AffinePartSort(LatticeUnion *List)
static int polylib_sqrt(int i)
int intcompare(const void *a, const void *b)
static int LinearPartCompare(const void *A, const void *B)
Bool LatticeIncludes(Lattice *A, Lattice *B)
LatticeUnion * SplitLattice(Matrix *, Matrix *, Matrix *)
LatticeUnion * LatticeSimplify(LatticeUnion *latlist)
void AffineSmith(Lattice *A, Lattice **U, Lattice **V, Lattice **Diag)
Lattice * LatticePreimage(Lattice *L, Matrix *G)
void LatticeUnion_Free(LatticeUnion *Head)
void PrintLatticeUnion(FILE *fp, char *format, LatticeUnion *Head)
Bool sameLattice(Lattice *A, Lattice *B)
int FindHermiteBasisofDomain(Polyhedron *A, Matrix **B)
Lattice * LatticeImage(Lattice *A, Matrix *M)
void PutRowLast(Matrix *X, int Rownumber)
void PutColumnLast(Matrix *X, int Columnnumber)
Matrix * Identity(unsigned size)
void PutRowFirst(Matrix *X, int Rownumber)
void PutColumnFirst(Matrix *X, int Columnnumber)
Matrix * RemoveColumn(Matrix *M, int Columnnumber)
int findHermiteBasis(Matrix *M, Matrix **Result)
Matrix * Matrix_Copy(Matrix const *Src)
int SolveDiophantine(Matrix *M, Matrix **U, Vector **X)
#define value_oppose(ref, val)
#define value_notzero_p(val)
#define value_notone_p(val)
#define value_lcm(ref, val1, val2)
#define value_decrement(ref, val)
#define value_zero_p(val)
#define value_assign(v1, v2)
#define value_increment(ref, val)
#define value_set_si(val, i)
#define value_addmul(ref, val1, val2)
#define value_division(ref, val1, val2)
#define value_multiply(ref, val1, val2)
#define value_print(Dst, fmt, val)
#define value_modulus(ref, val1, val2)
#define value_subtract(ref, val1, val2)
#define value_addto(ref, val1, val2)
void Matrix_Product(Matrix *Mat1, Matrix *Mat2, Matrix *Mat3)
Matrix * Matrix_Alloc(unsigned NbRows, unsigned NbColumns)
int Matrix_Inverse(Matrix *Mat, Matrix *MatInv)
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
void Matrix_Free(Matrix *Mat)
Polyhedron * DomainImage(Polyhedron *Pol, Matrix *Func, unsigned NbMaxConstrs)
void Domain_Free(Polyhedron *Pol)
#define POL_ENSURE_VERTICES(P)
#define POL_ENSURE_FACETS(P)
struct LatticeUnion * next
void Vector_Free(Vector *vector)