32 errormsg1(
"Matrix_Alloc",
"outofmem",
"out of memory space");
37 if (NbRows == 0 || NbColumns == 0) {
42 q = (Value **)malloc(NbRows *
sizeof(*q));
45 errormsg1(
"Matrix_Alloc",
"outofmem",
"out of memory space");
52 errormsg1(
"Matrix_Alloc",
"outofmem",
"out of memory space");
57 for (i = 0; i < NbRows; i++) {
85 q = (Value **)realloc(Mat->
p, NbRows *
sizeof(*q));
87 errormsg1(
"Matrix_Extend",
"outofmem",
"out of memory space");
92 p = (Value *)realloc(Mat->
p_Init, NbRows * Mat->
NbColumns *
sizeof(Value));
94 errormsg1(
"Matrix_Extend",
"outofmem",
"out of memory space");
100 for (i = Mat->
p_Init_size; i < Mat->NbColumns * NbRows; ++i)
106 for (i = 0; i < NbRows; i++) {
118 unsigned NbRows, NbColumns;
120 fprintf(Dst,
"%d %d\n", NbRows = Mat->
NbRows, NbColumns = Mat->
NbColumns);
121 if (NbColumns == 0) {
125 for (i = 0; i < NbRows; i++) {
127 for (j = 0; j < NbColumns; j++) {
155 for (i = 0; i < Mat->
NbRows; i++) {
157 c = fgets(
s, 1024, fp);
161 while (isspace(*c) && *c !=
'\n' && *c)
163 }
while (*c ==
'#' ||
166 errormsg1(
"Matrix_Read",
"baddim",
"not enough rows");
173 "Matrix_Read",
"warning",
174 "line longer than 1024 chars (ignored remaining chars till EOL)");
177 while (
n != EOF &&
n !=
'\n');
182 if (*c ==
'\n' || *c ==
'#' || *c ==
'\0') {
183 errormsg1(
"Matrix_Read",
"baddim",
"not enough columns");
187 for (z = c; *z; z++) {
188 if (*z ==
'\n' || *z ==
'#' || isspace(*z))
217 unsigned NbRows, NbColumns;
220 if (fgets(
s, 1024, fp) == NULL)
222 while ((*
s ==
'#' || *
s ==
'\n') ||
223 (sscanf(
s,
"%d %d", &NbRows, &NbColumns) < 2)) {
224 if (fgets(
s, 1024, fp) == NULL)
229 errormsg1(
"Matrix_Read",
"outofmem",
"out of memory space");
244 int nc,
nr, i, j, k, rank, reduced, pivotrow;
246 Value *temp1, *temp2;
252 errormsg1(
"Domlib",
"nullH",
"hermite: ? Null H");
257 temp1 = (Value *)malloc(nc *
sizeof(Value));
258 temp2 = (Value *)malloc(
nr *
sizeof(Value));
259 if (!temp1 || !temp2) {
260 errormsg1(
"Domlib",
"outofmem",
"out of memory space");
268 for (i = 0; i < nc; i++)
270 for (i = 0; i <
nr; i++)
274 fprintf(stderr,
"Start -----------\n");
277 for (k = 0, rank = 0; k < nc && rank <
nr; k = k + 1) {
280 fprintf(stderr,
"Working on col %d. Rank=%d ----------\n", k + 1,
293 for (i = rank + 1; i <
nr; i++) {
302 if (pivotrow != rank) {
310 fprintf(stderr,
"Exchange rows %d and %d -----------\n", rank + 1,
320 for (j = 0; j < nc; j++)
325 for (j = 0; j <
nr; j++)
330 for (j = 0; j <
nr; j++)
335 fprintf(stderr,
"Negate row %d -----------\n", rank + 1);
345 for (i = rank + 1; i <
nr; i++) {
358 for (j = 0; j < nc; j++) {
365 for (j = 0; j <
nr; j++) {
372 for (j = 0; j <
nr; j++) {
378 fprintf(stderr,
"row %d = row %d - %d row %d -----------\n", i + 1,
393 for (i = 0; i < rank; i++) {
408 for (j = 0; j < nc; j++) {
415 for (j = 0; j <
nr; j++) {
422 for (j = 0; j <
nr; j++) {
426 fprintf(stderr,
"row %d = row %d - %d row %d -----------\n", i + 1,
440 for (i = 0; i < nc; i++)
442 for (i = 0; i <
nr; i++)
462 errormsg1(
"DomRightHermite",
"outofmem",
"out of memory space");
475 errormsg1(
"DomRightHermite",
"outofmem",
"out of memory space");
480 for (i = 0; i <
nr; i++)
490 errormsg1(
"DomRightHermite",
"outofmem",
"out of memory space");
495 for (i = 0; i <
nr; i++)
505 for (i = 0; i <
nr; i++) {
506 for (j = i + 1; j <
nr; j++) {
533 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
537 for (i = 0; i <
nr; i++)
538 for (j = 0; j < nc; j++)
545 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
550 for (i = 0; i < nc; i++)
559 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
564 for (i = 0; i < nc; i++)
573 errormsg1(
"DomLeftHermite",
"outofmem",
"out of memory space");
577 for (i = 0; i <
nr; i++)
578 for (j = 0; j < nc; j++)
584 for (i = 0; i < nc; i++) {
585 for (j = i + 1; j < nc; j++) {
610 fprintf(stderr,
"Trying to invert a non-square matrix !\n");
629 for (i = 0; i < k; ++i) {
635 for (i = 0; i < k; ++i) {
641 for (j = i; j < k; ++j)
661 for (c = 0; c < k; ++c) {
678 for (j = 0; j < k; ++j) {
689 for (c = ((j > i) ? i : 0); c < k; ++c) {
694 for (c = 0; c < k; ++c) {
706 for (c = 0; c < k; ++c) {
717 for (j = 0; j < k; ++j) {
744 int last_column_index = P->
NbColumns - 1;
745 Value lcm, gcd, last_column_entry, s1;
758 for (k = 1; k < P->
NbRows; ++k) {
766 for (i = 0; i < X->
NbRows; ++i)
771 for (k = 0; k < P->
NbRows; ++k) {
790 for (i = 0; i < S->
NbRows; ++i) {
814 int NbRows, NbColumns, i, j;
815 Value **cm, *q, *cp1, *cp2;
822 for (i = 0; i < NbRows; i++) {
830 for (j = 1; j < NbColumns; j++) {
846 int NbRows, NbColumns, i, j;
847 Value **cm, *cp1, *cp2;
853 for (j = 0; j < NbColumns; j++) {
859 for (i = 1; i < NbRows; i++) {
875 unsigned NbRows, NbColumns;
876 Value **q1, **q2, *p1, *p3, sum;
884 fprintf(stderr,
"? Matrix_Product : incompatible matrix dimension\n");
893 for (i = 0; i < NbRows; i++) {
894 for (j = 0; j < NbColumns; j++) {
897 for (k = 0; k < Size; k++) {
925 fprintf(stderr,
"Trying to invert a non-square matrix !\n");
944 for (i = 0; i < k; ++i) {
950 for (i = 0; i < k; ++i) {
956 for (j = i; j < k; ++j)
976 for (c = 0; c < k; ++c) {
993 for (j = 0; j < k; ++j) {
1004 for (c = ((j > i) ? i : 0); c < k; ++c) {
1009 for (c = 0; c < k; ++c) {
1021 for (c = 0; c < k; ++c) {
1031 den = (Value *)malloc(k *
sizeof(Value));
1033 for (j = 0; j < k; ++j) {
1043 for (c = 0; c < k; c++)
1052 for (j = 0; j < k; ++j) {
1053 for (c = 0; c < k; c++) {
1060 for (j = 0; j < k; ++j) {
#define value_oppose(ref, val)
#define value_notzero_p(val)
#define value_divexact(ref, val1, val2)
#define value_gcd(ref, val1, val2)
#define value_notone_p(val)
#define value_absolute(ref, val)
#define value_decrement(ref, val)
#define value_zero_p(val)
#define value_assign(v1, v2)
#define value_set_si(val, i)
#define value_addmul(ref, val1, val2)
#define value_read(val, str)
#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)
void errormsg1(const char *f, const char *msgname, const char *msg)
static int hermite(Matrix *H, Matrix *U, Matrix *Q)
void Vector_Matrix_Product(Value *p1, Matrix *Mat, Value *p2)
void Matrix_Product(Matrix *Mat1, Matrix *Mat2, Matrix *Mat3)
void Matrix_Extend(Matrix *Mat, unsigned NbRows)
void Matrix_Vector_Product(Matrix *Mat, Value *p1, Value *p2)
Matrix * Matrix_Alloc(unsigned NbRows, unsigned NbColumns)
Matrix * Matrix_Read_Input(Matrix *Mat)
int Matrix_Inverse(Matrix *Mat, Matrix *MatInv)
void right_hermite(Matrix *A, Matrix **Hp, Matrix **Up, Matrix **Qp)
Matrix * Matrix_Read(void)
void Matrix_Print(FILE *Dst, const char *Format, Matrix *Mat)
Matrix * Matrix_Read_InputFile(Matrix *Mat, FILE *fp)
void rat_prodmat(Matrix *S, Matrix *X, Matrix *P)
void left_hermite(Matrix *A, Matrix **Hp, Matrix **Qp, Matrix **Up)
int MatInverse(Matrix *Mat, Matrix *MatInv)
Matrix * Matrix_ReadFile(FILE *fp)
void Matrix_Free(Matrix *Mat)
Value * value_alloc(int want, int *got)
void Vector_Set(Value *p, int n, unsigned length)
void value_free(Value *p, int size)
void Vector_Normalize_Positive(Value *p, int length, int pos)
void Vector_Gcd(Value *p, unsigned length, Value *min)
void Vector_Exchange(Value *p1, Value *p2, unsigned length)
void Vector_Copy(Value *p1, Value *p2, unsigned length)