1 /* spect.c -- the spectral test */
4 Copyright 1999 Free Software Foundation, Inc.
6 This file is part of the GNU MP Library.
8 The GNU MP Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
13 The GNU MP Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
21 /* T is upper dimension. Z_A is the LC multiplier, which is
22 relatively prime to Z_M, the LC modulus. The result is put in
23 rop[] with v[t] in rop[t-2]. */
25 /* BUGS: Due to lazy allocation scheme, maximum T is hard coded to MAXT. */
38 main (int argc, char *argv[])
40 const char usage[] = "usage: spect [-d] a m n\n";
44 mpf_t res[GMP_SPECT_MAXT], res_min[GMP_SPECT_MAXT], f_tmp;
50 for (f = 0; f < GMP_SPECT_MAXT; f++)
53 mpf_init (res_min[f]);
56 mpf_set_ui (res_min[0], 32768); /* 2^15 */
57 mpf_set_ui (res_min[1], 1024); /* 2^10 */
58 mpf_set_ui (res_min[2], 256); /* 2^8 */
59 mpf_set_ui (res_min[3], 64); /* 2^6 */
60 mpf_set_ui (res_min[4], 32); /* 2^5 */
62 while ((c = getopt (argc, argv, "dh")) != -1)
70 fputs (usage, stderr);
78 fputs (usage, stderr);
82 mpz_set_str (a, argv[0], 0);
83 mpz_set_str (m, argv[1], 0);
84 n = (unsigned int) atoi (argv[2]);
85 if (n + 1 > GMP_SPECT_MAXT)
86 n = GMP_SPECT_MAXT + 1;
88 spectral_test (res, n, a, m);
90 for (f = 0; f < n - 1; f++)
93 printf ("%d: v = ", f + 2);
94 mpf_out_str (stdout, 10, 4, res[f]);
96 #ifdef PRINT_RAISED_BY_TWO_AS_WELL
98 mpf_mul (f_tmp, res[f], res[f]);
99 mpf_out_str (stdout, 10, 4, f_tmp);
101 #endif /* PRINT_RAISED_BY_TWO_AS_WELL */
105 merit (f_tmp, f + 2, res[f], m);
106 mpf_out_str (stdout, 10, 4, f_tmp);
108 if (mpf_cmp (res[f], res_min[f]) < 0)
109 printf ("\t*** v too low ***");
110 if (mpf_get_d (f_tmp) < .1)
111 printf ("\t*** merit too low ***");
118 for (f = 0; f < GMP_SPECT_MAXT; f++)
121 mpf_clear (res_min[f]);