2 * test4000 - 4000 series of the regress.cal test suite
4 * Copyright (C) 1999 Ernest Bowen and Landon Curt Noll
6 * Primary author: Ernest Bowen
8 * Calc is open software; you can redistribute it and/or modify it under
9 * the terms of the version 2.1 of the GNU Lesser General Public License
10 * as published by the Free Software Foundation.
12 * Calc is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 * Public License for more details.
17 * A copy of version 2.1 of the GNU Lesser General Public License is
18 * distributed with calc under the filename COPYING-LGPL. You should have
19 * received a copy with calc; if not, write to Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * @(#) $Revision: 30.2 $
23 * @(#) $Id: test4000.cal,v 30.2 2013/08/11 08:41:38 chongo Exp $
24 * @(#) $Source: /usr/local/src/bin/calc/cal/RCS/test4000.cal,v $
26 * Under source code control: 1996/03/13 02:38:45
27 * File existed as early as: 1996
29 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
33 * Functions for testing and timing ptest, nextcand, prevcand.
35 * rlen(N) for N > 0 generates a random N-word positive integer.
37 * plen(N) for N > 0 generates an almost certainly prime positive
38 * integer whose word-count is about N.
40 * clen(N) for N > 0 generates a composite odd N-word integer.
42 * ptimes(str, N [, n [, count [, skip, [, verbose]]]])
43 * tests, and finds the runtime, for
44 * ptest(x, count, skip) for n random almost certainly prime integers x
45 * with word-count about N; n defaults to ceil(K1/abs(count)/(H1 + N^3)),
46 * count to COUNT, skip to SKIP.
48 * ctimes(str, N [, n [, count [, skip, [, verbose]]]])
49 * tests, and finds the runtime, for
50 * ptest(x, count, skip) for n random composite integers x with word-count
51 * about N; n defaults to ceil(K2/(H2 + N^3)), count to COUNT, skip
54 * crtimes(str,a,b,n, [,count [, skip, [, verbose]]])
55 * tests, and finds the runtime,
56 * for ptest(x, count, skip) for n random integers x between a and b;
57 * count defaults to COUNT, skip to SKIP.
59 * ntimes (str, N [,n, [, count [, skip [, residue [, modulus[,verb]]]]]]) tests
60 * and finds the runtime for nextcand(...) and prevcand (...) for
61 * n integers x with word-count about N, etc. n defaults to
62 * ceil(K3/(H3 + N^3));
64 * testnextcand(str, N [, n [, count [, skip [, residue [, modulus [, verb]]]]])
65 * performs tests of nextcand(x, count, skip, residue, modulus)
66 * for n values of x with word-count N; n defaults to
67 * ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0,
70 * testprevcand(str, N [, n [, count [, skip [, residue [, modulus [, verb]]]]])
71 * performs tests of prevcand(x, count, skip, residue, modulus)
72 * for n values of x with word-count N; n defaults to
73 * ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0,
78 defaultverbose = 1; /* default verbose value */
84 global BASE = 2^BASEB;
91 * internal test constants
104 if (!isint(N) || N <= 0)
105 quit "Bad argument for rlen";
106 return rand(BASE^(N-1), BASE^N);
109 define plen(N) = nextcand(rlen(N), 10, 0);
125 define ptimes(str, N, n, count, skip, verbose)
130 verbose = defaultverbose;
138 n = ceil(K1/abs(count)/(H1 + N^3));
146 for (i = 0; i < n; i++)
149 for (i = 0; i < n; i++) {
150 p = ptest(A[i], count, skip);
153 printf("*** Error for x = %d\n", A[i]);
160 printf("*** %d error(s)\n", m);
162 t = round(usertime() - t, 4);
164 printf("%d probable primes: time = %d\n", n, t);
166 printf("%d probable primes: passed\n", n);
173 define ctimes(str, N, n, count, skip, verbose)
175 local A, i, r, t, p, m;
179 verbose = defaultverbose;
187 n = ceil(K2/(H2 + N^3));
195 for (i = 0; i < n; i++)
198 for (i = 0; i < n; i++) {
199 p = ptest(A[i], count, skip);
202 printf("*** Error, what should be rare "
203 "has occurred for x = %d \n", A[i]);
210 printf("*** %d error(s)\n", m);
212 t = round(usertime() - t, 4);
214 printf("%d probable primes: time = %d\n", n, t);
216 printf("%d probable primes: passed\n", n);
223 define crtimes(str, a, b, n, count, skip, verbose)
225 local A, P, i, t, p, m;
228 verbose = defaultverbose;
242 for (i = 0; i < n; i++) {
244 P[i] = ptest(A[i], 20, 0);
247 for (i = 0; i < n; i++) {
248 p = ptest(A[i], count, skip);
251 printf("*** Apparent error for %s x = %d\n",
252 P[i] ? "prime" : "composite", A[i]);
259 printf("*** %d error(s)?\n", m);
261 t = round(usertime() - t, 4);
263 printf("%d probable primes: time = %d\n", n, t);
265 printf("%d probable primes: passed\n", n);
272 define ntimes(str, N, n, count, skip, residue, modulus, verbose)
274 local A, i, t, p, tnext, tprev;
277 verbose = defaultverbose;
284 n = ceil(K3/(H3 + N^3));
297 for (i = 0; i < n; i++)
300 for (i = 0; i < n; i++) {
301 p = nextcand(A[i], count, skip, residue, modulus);
303 tnext = round(usertime() - t, 4);
305 for (i = 0; i < n; i++) {
306 p = prevcand(A[i], count, skip, residue, modulus);
308 tprev = round(usertime() - t, 4);
310 printf("%d evaluations, nextcand: %d, "
311 "prevcand: %d\n", n, tnext, tprev);
315 define testnextcand(str, N, n, count, skip, residue, modulus, verbose)
320 verbose = defaultverbose;
328 n = ceil(K3/(H3 + N^3));
337 for (i = 0; i < n; i++) {
339 y = nextcand(x, count, skip, residue, modulus);
340 p = testnext1(x, y, count, skip, residue, modulus);
344 printf("*** Failure %d for x = %d\n", p, x);
350 printf("*** %d error(s)?\n", m);
352 printf("%d successful tests\n", n);
358 define testnext1(x, y, count, skip, residue, modulus)
362 if (!ptest(y, count, skip))
364 if (mne(y, residue, modulus))
369 define testprevcand(str, N, n, count, skip, residue, modulus, verbose)
374 verbose = defaultverbose;
382 n = ceil(K3/(H3 + N^3));
391 for (i = 0; i < n; i++) {
393 y = prevcand(x, count, skip, residue, modulus);
394 p = testprev1(x, y, count, skip, residue, modulus);
398 printf("*** Failure %d for x = %d\n", p, x);
404 printf("*** %d error(s)?\n", m);
406 printf("%d successful tests\n", n);
413 define testprev1(x, y, count, skip, residue, modulus)
417 if (!ptest(y, count, skip))
419 if (mne(y, residue, modulus))
425 * test4000 - perform all of the above tests a bunch of times
427 define test4000(v, tnum)
429 local n; /* test parameter */
432 * set test parameters
437 * test a lot of stuff
439 err += ptimes(strcat(str(tnum++),": ptimes(1,250)"), 1, 250,,,v);
440 err += ptimes(strcat(str(tnum++),": ptimes(3,50)"), 3, 50,,,v);
441 err += ptimes(strcat(str(tnum++),": ptimes(5,20)"), 5, 20,,,v);
443 err += ctimes(strcat(str(tnum++),": ctimes(1,7500)"), 1, 7500,,,v);
444 err += ctimes(strcat(str(tnum++),": ctimes(3,500)"), 3, 500,,,v);
445 err += ctimes(strcat(str(tnum++),": ctimes(5,200)"), 5, 200,,,v);
447 err += crtimes(strcat(str(tnum++),": crtimes(2^30,2^31,2500)"),
448 2^30, 2^31, 2500,,,v);
449 err += crtimes(strcat(str(tnum++),": crtimes(2^300,2^301,75)"),
450 2^300, 2^301, 75,,,v);
452 err += testprevcand(strcat(str(tnum++),": testprevcand(1,250)"),
454 err += testprevcand(strcat(str(tnum++),": testprevcand(3,25)"),
456 err += testprevcand(strcat(str(tnum++),": testprevcand(5,10)"),
459 err += testnextcand(strcat(str(tnum++),": testnextcand(1,250)"),
461 err += testnextcand(strcat(str(tnum++),": testnextcand(3,25)"),
463 err += testnextcand(strcat(str(tnum++),": testnextcand(5,10)"),
471 print "***", err, "error(s) found in testall";
473 print "no errors in testall";