22 for (temp = Head; temp != NULL; temp = temp->
next)
34 while (Head != NULL) {
66 fp = fopen(
"_debug",
"a");
67 fprintf(fp,
"\nEntered SAMEAFFINEPART \n");
71 for (i = 0; i < A->NbRows; i++)
72 if (
value_ne(A->p[i][A->NbColumns - 1], B->p[i][B->NbColumns - 1]))
88 fp = fopen(
"_debug",
"a");
89 fprintf(fp,
"\nEntered NULLATTICE \n");
95 for (j = 0; j < dimension; j++)
107 if(A == NULL || A->NbColumns == 0) {
111 for (
int j = 0; j < A->NbRows-1; j++) {
131 fp = fopen(
"_debug",
"a");
132 fprintf(fp,
"\nEntered ISLINEAR \n");
136 for (i = 0; i < A->NbRows - 1; i++)
313 fp = fopen(
"_debug",
"a");
314 fprintf(fp,
"\nEntered HOMOGENISE \n");
319 if (Forward ==
True) {
341 fp = fopen(
"_debug",
"a");
342 fprintf(fp,
"\nEntered LATTICE INCLUDES \n");
374 fp = fopen(
"_debug",
"a");
375 fprintf(fp,
"\nEntered SAME LATTICE \n");
379 if(A->NbRows != B->NbRows || A->NbColumns != B->NbColumns)
385 for (i = 0; i < A->NbRows; i++)
386 for (j = 0; j < A->NbColumns; j++)
387 if (
value_ne(HA->p[i][j], HB->p[i][j])) {
411 if (dimension <= A->NbRows) {
412 for (i = 0; i < dimension; i++)
413 for (j = 0; j < dimension; j++)
417 for (i = 0; i < A->NbRows; i++)
418 for (j = 0; j < A->NbRows; j++)
421 for (i = A->NbRows; i < dimension; i++)
422 for (j = 0; j < dimension; j++) {
426 for (i = A->NbRows; i < dimension; i++)
439 Result = (Lattice *)
Matrix_Alloc(A->NbRows - 1, A->NbColumns - 1);
440 for (i = 0; i < A->NbRows - 1; i++)
441 for (j = 0; j < A->NbColumns - 1; j++)
687 Lattice *B1 = NULL, *B2 = NULL, *newB1 = NULL, *newB2 = NULL,
688 *Intersection = NULL;
689 Matrix *U = NULL, *M1 = NULL, *M2 = NULL, *M1Inverse = NULL,
691 Matrix *Vinv, *V, *temp, *DiagMatrix;
699 fprintf(stderr,
"Lattice intersection = ");
704 fprintf(stderr,
"\nIn Lattice2LatticeUnion : the input lattices X and Y do "
705 "not have any common part\n");
715 fprintf(stderr,
"M1 = ");
717 fprintf(stderr,
"M2 = ");
721 int maxdim = (M1->NbColumns > M1->NbRows)? M1->NbColumns : M1->NbRows;
728 for (i = 0; i < M1->NbRows; i++) {
730 for (j = 0; j < M1->NbColumns; j++)
732 for( ; j < maxdim; j++)
736 for (
int j = 0; j < M1->NbColumns; j++)
743 M1Inverse->NbColumns = M1->NbRows;
744 M1Inverse->NbRows = M1->NbColumns;
750 fprintf(stderr,
"M1Inverse = ");
754 MtProduct =
Matrix_Alloc(M1Inverse->NbRows, M2->NbColumns);
768 for (i = 0; i < DiagMatrix->
NbRows; i++)
772 fprintf(stderr,
"B1 = ");
774 fprintf(stderr,
"B2 = ");
788 for(i=0 ; i<B1->NbRows; i++) {
789 for(
int j=0 ; j<B1->NbColumns; j++) {
795 for(
int j=0 ; j<B1->NbColumns; j++) {
800 for (i = 0; i < newB2->NbRows; i++)
802 value_set_si(newB1->p[i][newB2->NbColumns - 1], (i==newB2->NbColumns - 1));
804 Intersection->p[i][Intersection->NbColumns - 1]);
808 fprintf(stderr,
"newB2 = ");
810 fprintf(stderr,
"Diag = ");
840 fp = fopen(
"_debug",
"a");
841 fprintf(fp,
"\nEntered LATTICEDIFFERENCE \n");
846 fprintf(stderr,
"Entering LatDiff. A = ");
848 fprintf(stderr,
"B = ");
852 if (A->NbRows != B->NbRows) {
853 errormsg1(
"LatticeDifference",
"dimincomp",
854 "input lattices A and B have incompatible dimensions (rows)");
857 if (A->NbColumns != B->NbColumns) {
858 errormsg1(
"LatticeDifference",
"dimincomp",
859 "input lattices A and B have incompatible dimensions (columns)");
886 fprintf(stderr,
"Raw result = ");
890 fprintf(stderr,
"empty\n");
909 tempHead->next = NULL;
912 fprintf(stderr,
"avant simplification\n");
915 if ((Head != NULL)) {
918 fprintf(stderr,
"Simplified result = ");
945 for (i = 0; i < C->
NbRows; i++)
965 Value NumofTimes,
int Colnumber) {
975 while (tail->
next != NULL)
979 for (temp = Head; temp != NULL; temp = temp->
next) {
981 Lattice *tempMatrix, *H;
984 for (j = 0; j < B2->
NbRows; j++) {
986 B1->
p[j][Colnumber]);
995 tempMatrix->p[j][B2->
NbColumns - 1], maxval);
1300 fp = fopen(
"_debug",
"a");
1301 fprintf(fp,
"\nEntered ISLATTICE \n");
1308 if (
m->NbRows !=
m->NbColumns)
1311 for (i = 0; i <
m->NbColumns - 1; i++)
1369 Value cnt, aux, k, fac, tmp, foobar;
1371 if ((*InputList == NULL) || (InputList[0]->next == NULL))
1382 width = InputList[0]->
M->
NbRows - 1;
1385 for (temp = InputList[0]; temp != NULL; temp = temp->
next)
1387 for (i = 0; i < allfac.
count; i++) {
1393 if (i == allfac.
count) {
1404 for (; i < allfac.
count; i++) {
1408 if (*InputList == NULL) {
1424 for (temp = *InputList; temp != NULL; temp = temp->
next) {
1429 if (
value_ge(fac, (*InputList)->M->p[dim][dim])) {
1438 if (Present ==
True) {
1440 if (*ResultList == NULL)
1443 for (temp = *ResultList; temp->
next != NULL; temp = temp->
next)
1458 temp = InputList[0];
1459 while (temp != NULL) {
1460 if (
value_eq(temp->
M->
p[width][width], tmp)) {
1461 if (temp == InputList[0]) {
1463 temp = InputList[0] = temp->
next;
1509 for (i = 0; i < L1[0]->NbRows - 1; i++)
1510 for (j = 0; j <= i; j++) {
1511 if (
value_gt(L1[0]->p[i][j], L2[0]->p[i][j]))
1513 if (
value_lt(L1[0]->p[i][j], L2[0]->p[i][j]))
1531 for (temp = Head; temp != NULL; temp = temp->
next)
1534 Latlist = (Lattice **)malloc(
sizeof(Lattice *) * cnt);
1537 for (temp = Head; temp != NULL; temp = temp->
next)
1538 Latlist[cnt++] = temp->
M;
1543 for (temp = Head; temp != NULL; temp = temp->
next)
1544 temp->
M = Latlist[cnt++];
1564 for (i = 0; i < L1[0]->NbRows; i++) {
1565 if (
value_gt(L1[0]->p[i][L1[0]->NbColumns - 1],
1566 L2[0]->p[i][L2[0]->NbColumns - 1]))
1569 if (
value_lt(L1[0]->p[i][L1[0]->NbColumns - 1],
1570 L2[0]->p[i][L2[0]->NbColumns - 1]))
1587 for (tmp = List; tmp != NULL; tmp = tmp->
next)
1590 LatList = malloc(
sizeof(Lattice *) * cnt);
1593 for (tmp = List; tmp != NULL; tmp = tmp->
next)
1594 LatList[cnt++] = tmp->
M;
1599 for (tmp = List; tmp != NULL; tmp = tmp->
next)
1600 tmp->
M = LatList[cnt++];
1609 if ((A == NULL) || (B == NULL))
1612 for (i = 0; i < A->
M->
NbRows - 1; i++)
1633 if (curlist == NULL)
1636 if (curlist->
next == NULL) {
1637 curlist->
next = newlist[0];
1638 newlist[0] = curlist;
1643 for (i = 0; i < curlist->
M->
NbRows - 1; i++) {
1648 for (temp = curlist; temp != NULL; temp = temp->
next) {
1658 while (curr != NULL) {
1662 chng =
Simplify(&curlist, newlist, i);
1663 if (nextlist == NULL)
1667 for (tmp = nextlist; tmp->
next; tmp = tmp->
next)
1669 tmp->
next = curlist;
1671 change = (
Bool)(change | chng);
1681 for (temp = curlist; temp != NULL; temp = temp->
next) {
1688 if (curlist == NULL)
1691 if (*newlist == NULL)
1692 *newlist = nextlist;
1694 for (curr = *newlist; curr->
next != NULL; curr = curr->
next)
1696 curr->
next = nextlist;
1705 if ((A == NULL) || (B == NULL))
1707 for (i = 0; i < A->
M->
NbRows - 1; i++)
1708 for (j = 0; j <= i; j++)
1726 while (change ==
True) {
1731 while (curr != NULL) {
1768 result.
fac = malloc(tabsize *
sizeof(
int));
1770 while(div*div <= rest)
1775 if(result.
count == tabsize)
1778 result.
fac = realloc(result.
fac, tabsize *
sizeof(
int));
1785 div += (1 + (1&div));
1790 if(result.
count == tabsize)
1793 result.
fac = realloc(result.
fac, tabsize *
sizeof(
int));
1807 int size = (1<<(primes.
count));
1809 result.
fac = malloc(size *
sizeof(
int));
1812 for(
int mask=1; mask < size; mask++) {
1815 for(
int bits=0, rest=mask; rest ; bits++, rest>>=1) {
1817 val *= primes.
fac[bits];
1821 if(val > result.
fac[result.
count-1]) {
1902 Lattice *Tmp, *H, *Res;
1903 if(A->NbRows != B->NbRows){
1904 errormsg1(
"LatticeIntersection",
"dimincomp",
"incompatible dimensions!");
1907 #ifdef LATINTER_DEBUG
1908 fprintf(stderr,
"---Entering LatInter---\nMatrix A = ");
1910 fprintf(stderr,
"Matrix B = ");
1922 Tmp =
Matrix_Alloc(A->NbRows*2, A->NbColumns+B->NbColumns);
1925 errormsg1(
"LatticeIntersection",
"outofmem",
"Not enough memory space!");
1932 value_assign(Tmp->p[0][0], A->p[A->NbRows-1][A->NbColumns-1]);
1933 value_assign(Tmp->p[A->NbRows][0], A->p[A->NbRows-1][A->NbColumns-1]);
1936 for(
int i=1; i<A->NbRows; i++) {
1938 value_assign(Tmp->p[i+A->NbRows][0], A->p[i-1][A->NbColumns-1]);
1941 for(
int i = 1 ; i < A->NbRows; i++) {
1942 for(
int j = 1; j < A->NbColumns; j++){
1949 value_assign(Tmp->p[0][A->NbColumns], B->p[B->NbRows-1][B->NbColumns-1]);
1952 for (
int i = 1; i < B->NbRows; i++) {
1953 value_assign(Tmp->p[i][A->NbColumns], B->p[i-1][B->NbColumns-1]);
1956 for (
int i = 1; i < B->NbRows; i++){
1957 for (
int j = 1; j < B->NbColumns; j++) {
1958 value_assign(Tmp->p[i][j+A->NbColumns], B->p[i-1][j-1]);
1962 #ifdef LATINTER_DEBUG
1963 fprintf(stderr,
"H init = ");
1984 #ifdef LATINTER_DEBUG
1985 fprintf(stderr,
"\nH = ");
1995 for(
int col_num = H->NbColumns-1 ; col_num >= 0; col_num--) {
1997 for(i = 0; i < A->NbRows; i++) {
2001 if(i != A->NbRows) {
2009 #ifdef LATINTER_DEBUG
2010 fprintf(stderr,
"\nEmpty intersection\n");
2017 for (
int i = 0; i < Res->NbRows; i++) {
2018 for (
int j = 0; j < Res->NbColumns; j++) {
2019 value_assign(Res->p[i][j], H->p[i + H->NbRows - Res->NbRows][j + H->NbColumns - Res->NbColumns]);
2026 #ifdef LATINTER_DEBUG
2027 fprintf(stderr,
"\nLatticeIntersection result = ");
2029 fprintf(stderr,
"---Exiting LatInter---\n\n");
2051 for(
int i=0; i<A->
NbRows; i++) {
2054 for(
int j = A->
NbColumns-1; j > 0; j--) {
2062 for(
int i = A->
NbRows-1; i > 0; i--) {
2087 for (
int i = 0; i < A->
NbRows; i++) {
2089 for (
int j = 0; j < A->
NbColumns-1; j++) {
2094 for (
int j = 0; j < A->
NbColumns; j++) {
2096 for (
int i = 0; i < A->
NbRows-1; i++) {
Bool isNormalLattice(Matrix *A)
void PutRowLast(Matrix *X, int Rownumber)
void PutColumnLast(Matrix *X, int Columnnumber)
void PutRowFirst(Matrix *X, int Rownumber)
void PutColumnFirst(Matrix *X, int Columnnumber)
Matrix * Matrix_Copy(Matrix const *Src)
Lattice * EmptyLattice(int dimension)
LatticeUnion * LatticeUnion_Alloc(void)
Lattice * ExtractLinearPart(Lattice *A)
static void LinearPartSort(LatticeUnion *Head)
static factor prime_factors(int n)
Bool IsLattice(Matrix *m)
Lattice * LatticeIntersection(Lattice *A, Lattice *B)
void Matrix_Move_Homogeneous_Dim_First(Matrix *A)
static Bool Simplify(LatticeUnion **InputList, LatticeUnion **ResultList, int dim)
void AffineHermite(Lattice *A, Lattice **H, Matrix **U)
LatticeUnion * LatticeDifference(Lattice *A, Lattice *B)
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)
static Bool AlmostSameAffinePart(LatticeUnion *A, LatticeUnion *B)
static void AffinePartSort(LatticeUnion *List)
int intcompare(const void *a, const void *b)
static int LinearPartCompare(const void *A, const void *B)
Bool LatticeIncludes(Lattice *A, Lattice *B)
static void AddLattice(LatticeUnion *, Matrix *, Matrix *, Value, int)
LatticeUnion * SplitLattice(Matrix *, Matrix *, Matrix *)
LatticeUnion * LatticeSimplify(LatticeUnion *latlist)
void LatticeUnion_Free(LatticeUnion *Head)
void PrintLatticeUnion(FILE *fp, char *format, LatticeUnion *Head)
Bool sameLattice(Lattice *A, Lattice *B)
void Matrix_Move_Homogeneous_Dim_Last(Matrix *A)
#define VALUE_TO_INT(val)
#define value_notzero_p(val)
#define value_notone_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_modulus(ref, val1, val2)
#define value_addto(ref, val1, val2)
void errormsg1(const char *f, const char *msgname, const char *msg)
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 left_hermite(Matrix *A, Matrix **Hp, Matrix **Qp, Matrix **Up)
void Matrix_Free(Matrix *Mat)
struct lattice_union * next