This file is indexed.

/usr/share/calc/test4000.cal is in apcalc-common 2.12.4.4-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
/*
 * test4000 - 4000 series of the regress.cal test suite
 *
 * Copyright (C) 1999  Ernest Bowen and Landon Curt Noll
 *
 * Primary author:  Ernest Bowen
 *
 * Calc is open software; you can redistribute it and/or modify it under
 * the terms of the version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 *
 * Calc is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU Lesser General
 * Public License for more details.
 *
 * A copy of version 2.1 of the GNU Lesser General Public License is
 * distributed with calc under the filename COPYING-LGPL.  You should have
 * received a copy with calc; if not, write to Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * @(#) $Revision: 30.1 $
 * @(#) $Id: test4000.cal,v 30.1 2007/03/16 11:09:54 chongo Exp $
 * @(#) $Source: /usr/local/src/cmd/calc/cal/RCS/test4000.cal,v $
 *
 * Under source code control:	1996/03/13 02:38:45
 * File existed as early as:	1996
 *
 * Share and enjoy!  :-)	http://www.isthe.com/chongo/tech/comp/calc/
 */

/*
 * Functions for testing and timing ptest, nextcand, prevcand.
 *
 * rlen(N) for N > 0 generates a random N-word positive integer.
 *
 * plen(N) for N > 0 generates an almost certainly prime positive
 *	integer whose word-count is about N.
 *
 * clen(N) for N > 0 generates a composite odd N-word integer.
 *
 * ptimes(str, N [, n [, count [, skip, [, verbose]]]])
 *	tests, and finds the runtime, for
 *	ptest(x, count, skip) for n random almost certainly prime integers x
 *	with word-count about N; n defaults to ceil(K1/abs(count)/(H1 + N^3)),
 *	count to COUNT, skip to SKIP.
 *
 * ctimes(str, N [, n [, count [, skip, [, verbose]]]])
 *	tests, and finds the runtime, for
 *	ptest(x, count, skip) for n random composite integers x with word-count
 *	about N; n defaults to ceil(K2/(H2 + N^3)), count to COUNT, skip
 *	to SKIP.
 *
 * crtimes(str,a,b,n, [,count [, skip, [, verbose]]])
 *	tests, and finds the runtime,
 *	for ptest(x, count, skip) for n random integers x between a and b;
 *	count defaults to COUNT, skip to SKIP.
 *
 * ntimes (str, N [,n, [, count [, skip [, residue [, modulus[,verb]]]]]]) tests
 *	and finds the runtime for nextcand(...) and prevcand (...) for
 *	n integers x with word-count about N, etc. n defaults to
 *	ceil(K3/(H3 + N^3));
 *
 * testnextcand(str, N [, n [, count [, skip [, residue [, modulus [, verb]]]]])
 *	performs tests of nextcand(x, count, skip, residue, modulus)
 *	for n values of x with word-count N; n defaults to
 *	ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0,
 *	modulus to 1.
 *
 * testprevcand(str, N [, n [, count [, skip [, residue [, modulus [, verb]]]]])
 *	performs tests of prevcand(x, count, skip, residue, modulus)
 *	for n values of x with word-count N; n defaults to
 *	ceil(K3/(H3 + N^3)), count to COUNT, skip to SKIP, residue to 0,
 *	modulus to 1.
 */


defaultverbose = 1;	/* default verbose value */

/*
 * test defaults
 */
global BASEB = 32;
global BASE = 2^BASEB;
global COUNT = 5;
global SKIP = 0;
global RESIDUE = 0;
global MODULUS = 1;

/*
 * internal test constants
 */
global K1 = 2^15;
global H1 = 40;
global K2 = 2^17;
global H2 = 40;
global K3 = 2^10;
global H3 = 10;


define rlen(N)
{

	if (!isint(N) || N <= 0)
		quit "Bad argument for rlen";
	return rand(BASE^(N-1), BASE^N);
}

define plen(N) = nextcand(rlen(N), 10, 0);

define clen(N)
{
	local n, v;

	do {
		v = rlen(N);
		if (iseven(v))
			v++;
	}
	while
		(ptest(v, 10, 0));
	return v;
}

define ptimes(str, N, n, count, skip, verbose)
{
	local A, i, t, p, m;

	if (isnull(verbose))
		verbose = defaultverbose;
	if (verbose > 0) {
		print str:":",:;
	}
	m = 0;
	if (isnull(count))
		count = COUNT;
	if (isnull(n)) {
		n = ceil(K1/abs(count)/(H1 + N^3));
		if (verbose > 1) {
			print "n =",n;
		}
	}
	if (isnull(skip))
		skip = SKIP;
	mat A[n];
	for (i = 0; i < n; i++)
		A[i] = plen(N);
	t = usertime();
	for (i = 0; i < n; i++) {
		p = ptest(A[i], count, skip);
		if (!p) {
			if (verbose > 0) {
				printf("*** Error for x = %d\n", A[i]);
				m++;
			}
		}
	}
	if (verbose > 0) {
		if (m) {
			printf("*** %d error(s)\n", m);
		} else {
			t = round(usertime() - t, 4);
			if (verbose > 1) {
				printf("%d probable primes: time = %d\n", n, t);
			} else {
				printf("%d probable primes: passed\n", n);
			}
		}
	}
	return m;
}

define ctimes(str, N, n, count, skip, verbose)
{
	local A, i, r, t, p, m;


	if (isnull(verbose))
		verbose = defaultverbose;
	if (verbose > 0) {
		print str:":",:;
	}
	m = 0;
	if (isnull(count))
		count = COUNT;
	if (isnull(n)) {
		n = ceil(K2/(H2 + N^3));
		if (verbose > 1) {
			print "n =",n;
		}
	}
	if (isnull(skip))
		skip = SKIP;
	mat A[n];
	for (i = 0; i < n; i++)
		A[i] = clen(N);
	t = usertime();
	for (i = 0; i < n; i++) {
		p = ptest(A[i], count, skip);
		if (p) {
			if (verbose > 0) {
				printf("*** Error, what should be rare has occurred for x = %d \n", A[i]);
				m++;
			}
		}
	}
	if (verbose > 0) {
		if (m) {
			printf("*** %d error(s)\n", m);
		} else {
			t = round(usertime() - t, 4);
			if (verbose > 1) {
				printf("%d probable primes: time = %d\n", n, t);
			} else {
				printf("%d probable primes: passed\n", n);
			}
		}
	}
	return m;
}

define crtimes(str, a, b, n, count, skip, verbose)
{
	local A, P, i, t, p, m;

	if (isnull(verbose))
		verbose = defaultverbose;
	if (verbose > 0) {
		print str:":",:;
	}
	m = 0;
	if (b < a)
		swap(a,b);
	b++;
	if (isnull(count))
		count = COUNT;
	if (isnull(skip))
		skip = SKIP;
	mat A[n];
	mat P[n];
	for (i = 0; i < n; i++) {
		A[i] = rand(a,b);
		P[i] = ptest(A[i], 20, 0);
	}
	t = usertime();
	for (i = 0; i < n; i++) {
		p = ptest(A[i], count, skip);
		if (p != P[i]) {
			if (verbose > 0) {
				printf("*** Apparent error for %s x = %d\n",
					P[i] ? "prime" : "composite", A[i]);
				++m;
			}
		}
	}
	if (verbose > 0) {
		if (m) {
			printf("*** %d error(s)?\n", m);
		} else {
			t = round(usertime() - t, 4);
			if (verbose > 1) {
				printf("%d probable primes: time = %d\n", n, t);
			} else {
				printf("%d probable primes: passed\n", n);
			}
		}
	}
	return m;
}

define ntimes(str, N, n, count, skip, residue, modulus, verbose)
{
	local A, i, t, p, tnext, tprev;

	if (isnull(verbose))
		verbose = defaultverbose;
	if (verbose > 0) {
		print str:":",:;
	}
	if (isnull(count))
		count = COUNT;
	if (isnull(n)) {
		n = ceil(K3/(H3 + N^3));
		if (verbose > 1) {
			print "n =",n;
		}
	}
	if (isnull(skip))
		skip = SKIP;
	if (isnull(residue))
		residue = RESIDUE;
	if (isnull(modulus))
		modulus = MODULUS;

	mat A[n];
	for (i = 0; i < n; i++)
		A[i] = rlen(N);
	t = usertime();
	for (i = 0; i < n; i++) {
		p = nextcand(A[i], count, skip, residue, modulus);
	}
	tnext = round(usertime() - t, 4);
	t = usertime();
	for (i = 0; i < n; i++) {
		p = prevcand(A[i], count, skip, residue, modulus);
	}
	tprev = round(usertime() - t, 4);
	if (verbose > 0) {
		printf("%d evaluations, nextcand: %d, prevcand: %d\n", n, tnext, tprev);
	}
}

define testnextcand(str, N, n, count, skip, residue, modulus, verbose)
{
	local p, x, y, i, m;

	if (isnull(verbose))
		verbose = defaultverbose;
	if (verbose > 0) {
		print str:":",:;
	}
	m = 0;
	if (isnull(count))
		count = COUNT;
	if (isnull(n)) {
		n = ceil(K3/(H3 + N^3));
		print "n =",n;
	}
	if (isnull(skip))
		skip = SKIP;
	if (isnull(residue))
		residue = RESIDUE;
	if (isnull(modulus))
		modulus = MODULUS;
	for (i = 0; i < n; i++) {
		x = rlen(N);
		y = nextcand(x, count, skip, residue, modulus);
		p = testnext1(x, y, count, skip, residue, modulus);
		if (p) {
			m++;
			if (verbose > 1) {
				printf("*** Failure %d for x = %d\n", p, x);
			}
		}
	}
	if (verbose > 0) {
		if (m) {
			printf("*** %d error(s)?\n", m);
		} else {
			printf("%d successful tests\n", n);
		}
	}
	return m;
}

define testnext1(x, y, count, skip, residue, modulus)
{
	if (y <= x)
		return 1;
	if (!ptest(y, count, skip))
		return 2;
	if (mne(y, residue, modulus))
		return 3;
	return 0;
}

define testprevcand(str, N, n, count, skip, residue, modulus, verbose)
{
	local p, x, y, i, m;

	if (isnull(verbose))
		verbose = defaultverbose;
	if (verbose > 0) {
		print str:":",:;
	}
	m = 0;
	if (isnull(count))
		count = COUNT;
	if (isnull(n)) {
		n = ceil(K3/(H3 + N^3));
		print "n =",n;
	}
	if (isnull(skip))
		skip = SKIP;
	if (isnull(residue))
		residue = RESIDUE;
	if (isnull(modulus))
		modulus = MODULUS;
	for (i = 0; i < n; i++) {
		x = rlen(N);
		y = prevcand(x, count, skip, residue, modulus);
		p = testprev1(x, y, count, skip, residue, modulus);
		if (p) {
			m++;
			if (verbose > 1) {
				printf("*** Failure %d for x = %d\n", p, x);
			}
		}
	}
	if (verbose > 0) {
		if (m) {
			printf("*** %d error(s)?\n", m);
		} else {
			printf("%d successful tests\n", n);
		}
	}
	return m;
}


define testprev1(x, y, count, skip, residue, modulus)
{
	if (y >= x)
		return 1;
	if (!ptest(y, count, skip))
		return 2;
	if (mne(y, residue, modulus))
		return 3;
	return 0;
}

/*
 * test4000 - perform all of the above tests a bunch of times
 */
define test4000(v, tnum)
{
	local n;	/* test parameter */

	/*
	 * set test parameters
	 */
	srand(4000e4000);

	/*
	 * test a lot of stuff
	 */
	err += ptimes(strcat(str(tnum++),": ptimes(1,250)"), 1, 250,,,v);
	err += ptimes(strcat(str(tnum++),": ptimes(3,50)"), 3, 50,,,v);
	err += ptimes(strcat(str(tnum++),": ptimes(5,20)"), 5, 20,,,v);

	err += ctimes(strcat(str(tnum++),": ctimes(1,7500)"), 1, 7500,,,v);
	err += ctimes(strcat(str(tnum++),": ctimes(3,500)"), 3, 500,,,v);
	err += ctimes(strcat(str(tnum++),": ctimes(5,200)"), 5, 200,,,v);

	err += crtimes(strcat(str(tnum++),": crtimes(2^30,2^31,2500)"),
		2^30, 2^31, 2500,,,v);
	err += crtimes(strcat(str(tnum++),": crtimes(2^300,2^301,75)"),
		2^300, 2^301, 75,,,v);

	err += testprevcand(strcat(str(tnum++),": testprevcand(1,250)"),
		1, 250, ,,,,v);
	err += testprevcand(strcat(str(tnum++),": testprevcand(3,25)"),
		3, 25, ,,,,v);
	err += testprevcand(strcat(str(tnum++),": testprevcand(5,10)"),
		5, 10, ,,,,v);

	err += testnextcand(strcat(str(tnum++),": testnextcand(1,250)"),
		1, 250, ,,,,v);
	err += testnextcand(strcat(str(tnum++),": testnextcand(3,25)"),
		3, 25, ,,,,v);
	err += testnextcand(strcat(str(tnum++),": testnextcand(5,10)"),
		5, 10, ,,,,v);

	/*
	 * report results
	 */
	if (v > 1) {
		if (err) {
			print "***", err, "error(s) found in testall";
		} else {
			print "no errors in testall";
		}
	}
	return tnum;
}