From: <jay...@us...> - 2011-02-03 19:04:03
|
Revision: 408 http://ggnfs.svn.sourceforge.net/ggnfs/?rev=408&view=rev Author: jaysonking Date: 2011-02-03 19:03:57 +0000 (Thu, 03 Feb 2011) Log Message: ----------- If the input has a "m:" line, use it for verification instead of assuming that the second poly is always linear. If e.g. the second poly is non-linear, the verification inexplicably fails even if the correct "m:" is input. Make it nicer. Modified Paths: -------------- trunk/src/experimental/lasieve4_64/input-poly.c trunk/src/lasieve4/input-poly.c Modified: trunk/src/experimental/lasieve4_64/input-poly.c =================================================================== --- trunk/src/experimental/lasieve4_64/input-poly.c 2011-02-02 11:14:45 UTC (rev 407) +++ trunk/src/experimental/lasieve4_64/input-poly.c 2011-02-03 19:03:57 UTC (rev 408) @@ -150,8 +150,8 @@ i32_t *bdeg, mpz_t m, FILE *fp) /*******************************************************/ { char token[256], value[512], thisLine[1024]; - int i, j, cont=1; - mpz_t tmp, tmp2, mpow; + int i, j, cont=1, have_m=0; + mpz_t tmpA, tmpB; *adeg = *bdeg = 0; *A = xmalloc(9*sizeof(**A)); /* plenty o' room. */ @@ -170,6 +170,7 @@ mpz_set_str(N, value, 10); } else if (strncmp(token, "m:", 2)==0) { mpz_set_str(m, value, 10); + have_m=1; } else if ((token[0]=='c') && (token[1] >= '0') && (token[1] <= '8')) { mpz_set_str((*A)[token[1]-'0'], value, 10); *adeg = MAX(*adeg, token[1]-'0'); @@ -182,43 +183,45 @@ } if (feof(fp)) cont=0; } - if (*bdeg == 0) { + + if (have_m == 0) { /* recover m from the linear poly */ + if (*bdeg == 1) { /* assume *B is linear (it usually is) */ + mpz_invert(m, (*B)[1], N); + mpz_mul(m, m, (*B)[0]); + mpz_neg(m, m); + mpz_mod(m, m, N); + } else { + complain("could not find m\n"); + } + } else if (*bdeg == 0) { /* monic linear poly may be omitted */ mpz_set_ui((*B)[1], 1); mpz_neg((*B)[0], m); *bdeg=1; } /* Verify the polynomials: */ - mpz_init(tmp); mpz_init(tmp2); mpz_init(mpow); - mpz_set_ui(tmp, 0); - mpz_set_ui(mpow, 1); - - if (*bdeg) { - mpz_neg(m, (*B)[0]); /* m for temporary use */ - for(i=0; i<=*adeg; i++) { - mpz_mul(tmp2, mpow, (*A)[i]); - for(j=i; j <= *adeg; j++) - mpz_mul(tmp2, tmp2, (*B)[1]); - mpz_add(tmp, tmp, tmp2); - mpz_mul(mpow, mpow, m); - } - } else { - for (i=*adeg; i>=0; i--) { - mpz_mul(tmp, tmp, m); - mpz_add(tmp, tmp, (*A)[i]); - } + mpz_init_set(tmpA, (*A)[*adeg]); + for (i = *adeg - 1; i >= 0; i--) { + mpz_mul(tmpA, tmpA, m); + mpz_add(tmpA, tmpA, (*A)[i]); + mpz_mod(tmpA, tmpA, N); } - mpz_mod(tmp, tmp, N); - if (mpz_sgn(tmp)) { - printf("Error: the polynomials don't have a common root:\n"); + mpz_init_set(tmpB, (*B)[*bdeg]); + for (i = *bdeg - 1; i >= 0; i--) { + mpz_mul(tmpB, tmpB, m); + mpz_add(tmpB, tmpB, (*B)[i]); + mpz_mod(tmpB, tmpB, N); + } + if (mpz_sgn(tmpA) || mpz_sgn(tmpB)) { + printf("Error: m is not a common root of the polynomials:\n"); for (i=0; i<=*adeg; i++) - printf("c%d: %s\n", i, mpz_get_str(token, 10, (*A)[i])); + printf("c%d: %s\n", i, mpz_get_str(value, 10, (*A)[i])); for (i=0; i<=*bdeg; i++) - printf("Y%d: %s\n", i, mpz_get_str(token, 10, (*B)[i])); + printf("Y%d: %s\n", i, mpz_get_str(value, 10, (*B)[i])); printf("n: "); mpz_out_str(NULL,10,N); exit(-1); } - mpz_clear(tmp2); mpz_clear(mpow); mpz_clear(tmp); + mpz_clear(tmpA); mpz_clear(tmpB); } #endif Modified: trunk/src/lasieve4/input-poly.c =================================================================== --- trunk/src/lasieve4/input-poly.c 2011-02-02 11:14:45 UTC (rev 407) +++ trunk/src/lasieve4/input-poly.c 2011-02-03 19:03:57 UTC (rev 408) @@ -148,8 +148,8 @@ i32_t *bdeg, mpz_t m, FILE *fp) /*******************************************************/ { char token[256], value[512], thisLine[1024]; - int i, j, cont=1; - mpz_t tmp, tmp2, mpow; + int i, j, cont=1, have_m=0; + mpz_t tmpA, tmpB; *adeg = *bdeg = 0; *A = xmalloc(9*sizeof(**A)); /* plenty o' room. */ @@ -168,6 +168,7 @@ mpz_set_str(N, value, 10); } else if (strncmp(token, "m:", 2)==0) { mpz_set_str(m, value, 10); + have_m=1; } else if ((token[0]=='c') && (token[1] >= '0') && (token[1] <= '8')) { mpz_set_str((*A)[token[1]-'0'], value, 10); *adeg = MAX(*adeg, token[1]-'0'); @@ -180,41 +181,45 @@ } if (feof(fp)) cont=0; } - if (*bdeg == 0) { + + if (have_m == 0) { /* recover m from the linear poly */ + if (*bdeg == 1) { /* assume *B is linear (it usually is) */ + mpz_invert(m, (*B)[1], N); + mpz_mul(m, m, (*B)[0]); + mpz_neg(m, m); + mpz_mod(m, m, N); + } else { + complain("could not find m\n"); + } + } else if (*bdeg == 0) { /* monic linear poly may be omitted */ mpz_set_ui((*B)[1], 1); mpz_neg((*B)[0], m); *bdeg=1; } /* Verify the polynomials: */ - mpz_init(tmp); mpz_init(tmp2); mpz_init(mpow); - mpz_set_ui(tmp, 0); - mpz_set_ui(mpow, 1); - - if (*bdeg) { - mpz_neg(m, (*B)[0]); /* m for temporary use */ - for(i=0; i<=*adeg; i++) { - mpz_mul(tmp2, mpow, (*A)[i]); - for(j=i; j <= *adeg; j++) - mpz_mul(tmp2, tmp2, (*B)[1]); - mpz_add(tmp, tmp, tmp2); - mpz_mul(mpow, mpow, m); - } - } else { - for (i=*adeg; i>=0; i--) { - mpz_mul(tmp, tmp, m); - mpz_add(tmp, tmp, (*A)[i]); - } + mpz_init_set(tmpA, (*A)[*adeg]); + for (i = *adeg - 1; i >= 0; i--) { + mpz_mul(tmpA, tmpA, m); + mpz_add(tmpA, tmpA, (*A)[i]); + mpz_mod(tmpA, tmpA, N); } - mpz_mod(tmp, tmp, N); - if (mpz_sgn(tmp)) { - printf("Error: the polynomials don't have a common root:\n"); + mpz_init_set(tmpB, (*B)[*bdeg]); + for (i = *bdeg - 1; i >= 0; i--) { + mpz_mul(tmpB, tmpB, m); + mpz_add(tmpB, tmpB, (*B)[i]); + mpz_mod(tmpB, tmpB, N); + } + if (mpz_sgn(tmpA) || mpz_sgn(tmpB)) { + printf("Error: m is not a common root of the polynomials:\n"); for (i=0; i<=*adeg; i++) - printf("c%d: %s\n", i, mpz_get_str(token, 10, (*A)[i])); + printf("c%d: %s\n", i, mpz_get_str(value, 10, (*A)[i])); for (i=0; i<=*bdeg; i++) - printf("Y%d: %s\n", i, mpz_get_str(token, 10, (*B)[i])); + printf("Y%d: %s\n", i, mpz_get_str(value, 10, (*B)[i])); + printf("n: "); + mpz_out_str(NULL,10,N); exit(-1); } - mpz_clear(tmp2); mpz_clear(mpow); mpz_clear(tmp); + mpz_clear(tmpA); mpz_clear(tmpB); } #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |