Re: [PrimeNumbers] Re: gmp-ecm-4c-r3
- On Sun, 30 September 2001, jfoug@... wrote:
> --- In primenumbers@y..., Phil Carmody <fatphil@a...> wrote:My cat below was a bad example, as that closes the pipe.
> > On Sat, 29 September 2001, Jim Fougeron wrote:
> > > I will be uploading a newer version of GMPECM shortly. This
> version contains these new things:
> > >
> > > 1. reads the entire file and converts all to GMP numbers. This
> is done so that the file only needs to be read one time, so that -i
> file and < file can behave the same, and so that other tracking can
> be done.
> > >
> > > 1.a If GMPECM detects that stdin is NOT redirected and that -i
> was not used, it does NOT try to read all numbers before operating.
> This still allows the user to type numbers into GMPECM.
> > What if the input is redirected output from another program?
> > For example
> Does not matter. The program automatically detects this, and it is
> treated the same as ecm < compositesall
cat | ecm 10000
just sits there doing nothing. The program can no longer be used in a pipe. Try that with the old code, and your new code - you'll see that the old code behaves as you'd expect it, but the new one just hangs there.
| really _isn't_ the same as < at all. One is a pipe which will block until closed or given more data, the other is a file which will return EOF.
> > cat composites1 composites2 composites3 | ecm ...I was just thinking of the code not far after line 700
> > Apart from that query, it looks fantastic.
> > (Though I think there are some simplifications that can be made in
> non-critical places, at least e.g. if a found factor takes 24 miller-
> rabins to prove composite...)
> No, to test for "primeness" requires 25 RM tests, some trial
> factoring, and 1 Fermat test. As soon as GMP knows the number is
> composite, it returns from that test. Even though it is listed as
> mpz_probable_prime(n,25) do not exect 25 loops of RM to be needed
> to know something is composite, usually the Fermat test will suffice,
> but if not, the first or second MR will probably find out it is
(I've had to change a few things to get it to compile, as the code has K&R signitures, and C++ comments, so was strictly neither valid C nor valid C++)
Printf("Found probable prime factor");
Printf("Found COMPOSITE factor");
Printf(" of %u digits: ",nb_digits(p));
if (mpz_probab_prime_p(p,25) && nb_digits(p)>=48)
Printf("Report your potential champion to Richard Brent <rpb@...>\n");
The second call to mpz_probab_prime_p is unnecessary, and the if could be moved inside the case it's a subset of.
Sure, 24 M-R's before finding it's a composite is unlikely, but it's just a neatness thing, that's all.
Actually, while I'm here, I had other problems compiling other bits too
Near line 550:
srandom(time(NULL) + getpid()); /* thanks to Conrad Curry */
# ifdef ANSIONLY
struct tm tp;
tp = *localtime(&timer);
srand(tp.tm_hour * 3600 + tp.tm_min * 60 + tp.tm_sec);
struct timeval tp;
srand48(65536 * tp.tv_sec + tp.tv_usec + getpid());
used to be
but ANSIONLY was defined as
which meant that the line translated to
which shouldn't work in any conforming compiler.
The other solution was to change the #define to provide a real value, but that was no longer a peephole solution.
> Yes, there are certainly simplifications which can be made. That isDo that to files, sure, but not to pipes. Pipes are more like interactive behaviour, kind-of semi-infinite. Files are finite.
> why I build an array of GMP numbers and pre-read the file.
struct stat statstruct;
/* is a regular file,
and can be read in a finite amount of time
/* is a fifo or a socket, (maybe a terminal)
Mathematics should not have to involve martyrdom;
Support Eric Weisstein, see http://mathworld.wolfram.com
Find the best deals on the web at AltaVista Shopping!