Files
calc/help/prevcand
2017-05-21 15:38:25 -07:00

86 lines
2.9 KiB
Plaintext

NAME
prevcand - previous candidate for primeness
SYNOPSIS
prevcand(n [,count [, skip [, residue [, modulus]]]])
TYPES
n integer
count integer with absolute value less than 2^24, defaults to 1
skip integer, defaults to 1
residue integer, defaults to 0
modulus integer, defaults to 1
return integer
DESCRIPTION
The sign of n is ignored; in the following it is assumed that n >= 0.
prevcand(n, count, skip, residue, modulus) returns the greatest
positive integer i less than abs(n) expressible as
residue + k * modulus, where k is an integer, for which
ptest(i,count,skip) == 1, or if there is no such integer i, zero.
If n < 2^32, count >= 0, and the returned value i is not zero, i is
definitely prime. If n > 2^32, count != 0, and i is not zero,
i is probably prime, particularly if abs(count) is greater than 1.
With the default argument values, if n > 2, prevcand(n) returns the a
probably prime integer i less than n such that every integer
between i and n is composite.
If skip == 0, the bases used in the probabilistic test are random
and then the probability that the returned value is composite is
less than 1/4^abs(count).
If skip == 1 (the default value) the bases used in the probabilistic
test are the first abs(count) primes 2, 3, 5, ...
For other values of skip, the bases used are the abs(count) consecutive
integer skip, skip + 1, ...
If modulus = 0, the only values that may be returned are zero and the
value of residue. The latter is returned if it is positive, less
than n, and is such that ptest(residue, count, skip) = 1.
RUNTIME
The runtime for v = prevcand(n, ...) will depend strongly on the
number and nature of the integers between n and v. If this number
is reasonably large the size of count is largely irrelevant as the
compositeness of the numbers between n and v will usually be
determined by the test for small prime factors or one pseudoprime
test with some base b. If N > 1, count should be positive so that
candidates divisible by small primes will be passed over quickly.
On the average for random n with large word-count N, the runtime
seems to be between roughly K/N^3 some constant K.
EXAMPLE
> print prevcand(50), prevcand(2), prevcand(125,-1), prevcand(125,-2)
47 1 113 113
> print prevcand(100,1,1,1,6), prevcand(100,1,1,-1,6)
97 89
> print prevcand(100,1,1,2,6), prevcand(100,1,1,4,6),
2 0
> print prevcand(100,1,1,53,0), prevcand(100,1,1,53,106)
53 53
> print prevcand(125,1,3), prevcand(125,-1,3), prevcand(125,-2,3)
113 121 113
> print prevcand(2e60, 1, 1, 31, 1e30)
1999999999999999999999999999914000000000000000000000000000031
LIMITS
none
LIBRARY
int zprevcand(ZVALUE n, long count, long skip, ZVALUE res, ZVALUE mod,
ZVALUE *cand)
SEE ALSO
nextcand, ptest