Diophantine linear system solving: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 1,644: | Line 1,644: | ||
// algorithms via lattice basis reduction,' |
// algorithms via lattice basis reduction,' |
||
// Experimental Mathematics 7 (1998), no.2, pp.125-136 |
// Experimental Mathematics 7 (1998), no.2, pp.125-136 |
||
// Code : |
// Code : standard C |
||
// compile with (gnu compiler): |
|||
// gcc filename.c -o diophantine -lm |
|||
#include <stdio.h> |
#include <stdio.h> |
||
Line 1,654: | Line 1,656: | ||
// ---- NOTE ---- |
// ---- NOTE ---- |
||
// these next few functions are useful to allocate and free the |
// these next few functions are useful to allocate and free the |
||
// array d[] and the matrices la[][] and a[][]. |
// array d[] and the matrices la[][] and a[][]. (Numerical Recipes in C) |
||
// useful to deal with negative array indices. |
// useful to deal with negative array indices. |
||
#define NR_END 1 |
#define NR_END 1 |
||
#define FREE_ARG char* |
#define FREE_ARG char* |
||
void nrerror(char error_text[]) |
void nrerror(char error_text[]) |
||
/* |
/* error handler */ |
||
{ |
{ |
||
fprintf(stderr,"Numerical Recipes run-time error...\n"); |
fprintf(stderr,"Numerical Recipes run-time error...\n"); |
||
Line 1,674: | Line 1,677: | ||
v = (double *)calloc((size_t) ((nh - nl + 1 + NR_END)), sizeof(double)); |
v = (double *)calloc((size_t) ((nh - nl + 1 + NR_END)), sizeof(double)); |
||
if ( |
if (v) nrerror("allocation failure in dvector()"); |
||
return v - nl + NR_END; |
return v - nl + NR_END; |
||
} |
} |
||
Line 1,839: | Line 1,842: | ||
//int i, j, k, r, s, t; bool sw = false; |
//int i, j, k, r, s, t; bool sw = false; |
||
int64_t r = 0, s = 0, sw = 0; |
int64_t r = 0, s = 0, sw = 0; |
||
char g |
char *g = alloca(1024); |
||
for (r = 0; r <= n - 1; r++) { |
for (r = 0; r <= n - 1; r++) { |
||
Line 1,879: | Line 1,882: | ||
{ |
{ |
||
int64_t l[m+1][mn+1], p[mn+1], k = 0, r = 0, s = 0; |
int64_t l[m+1][mn+1], p[mn+1], k = 0, r = 0, s = 0; |
||
char g |
char *g = alloca(1024); double q = 0; |
||
for (s = 0; s <= mn; s++) { |
for (s = 0; s <= mn; s++) { |
||
Line 1,885: | Line 1,888: | ||
// store lengths and max. length in column |
// store lengths and max. length in column |
||
// for pretty output |
// for pretty output |
||
char tmpg |
char *tmpg = alloca(1024); |
||
sprintf(tmpg, "%f", fabs(a[r][s])); |
sprintf(tmpg, "%f", fabs(a[r][s])); |
||
l[r][s] = strlen(tmpg); |
l[r][s] = strlen(tmpg); |