[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

871.0. "Performance of simple factoring program." by 37993::COOPER (Topher Cooper) Wed May 11 1988 16:45

    For a given N > 0 --
    
    Assume I have an ordered (smallest to largest) list of all the primes
    <= sqrt(N).  I am given a value, V, selected uniformly from the
    range 2..N.  I wish to factor it by checking it mod 2, then mod
    3, ... mod L, where L is the greatest prime <= sqrt(V).  When I
    find a "p" s.t. V mod p = 0, I register p as a factor, replace V
    with V' = V/p, and repeat the process.  (In other words, I use the
    obvious algorithm).
    
    Assume that performance time is dominated by the cost of a mod
    operation.
    
    Two questions:
    
    	1) What is the expected time to find the first (smallest prime)
    	   factor?
    
    	2) What is the expected time to factor a number?
    
    For a prime number the answer to the first question is the same
    as the answer to the second: the number of primes <= sqrt(V).
    
    For an even number the answer to the first question is 1, and this
    applies 1/2 the time.
    
    Similarly for a number evenly divisible by 3 but not 2, the answer to
    the first question is 2, and this applies 1/6 of the time.
    
    For a number evenly divisible by 5 but not either 3 or 2, the answer
    to the fist question is 3, and this applies 1/15 of the time.
    
    But what are the general answers?
    
    					Topher
T.RTitleUserPersonal
Name
DateLines
871.1Oy!SSDEVO::LARYTue May 17 1988 03:4554
I suspect that this is an extraordinarily difficult function to find.

Here's a microstep in what may be the right direction:

Problem: for large p, p prime, what is the probability that a random integer
N (ignoring the difficulty of picking random integers) is divisible by p but
by no smaller prime?

To approximate this answer, look at the interval [0,p!).
The pattern of the numbers we are looking for in this interval will be
repeated in [p!,2*p!), [2*p!,3*p!), etc, so the density of such numbers
in this interval (number of occurrences divided by p!) is the probability
we seek.

The numbers which are divisible by p but by no smaller prime are:

p,   p*p1,   p*p2,   ...	where p1, p2, etc are the 1st, 2d,
p^2, p^2*p1, p^2*p2, ...	etc. primes > p
p^3, p^3*p1, p^3*p2, ...

How many numbers are enumerated here? Consider the first line of the
enumeration. If p*x is less than p! then x must be less than p!/p;
but we must exclude all x between 2 and p inclusive, and all non-prime x.

Let pi(n) be the number of primes < n. Then the number of entries on the
first line of the enumeration is pi(p!/p)-pi(p).
Similiarly, the number of entries on the second line is pi(p!/p^2)-pi(p), etc.
There are [ln(p!)/ln(p)] lines in the enumeration, and the last line is
a special case, having exactly one element.

Since p is large, there are some approximations that can be used to simplify
things:

	pi(n) = n/ln(n)			(some famous theorem or other;
					 there may be a constant of
					 proportionality involved)

	ln(p!) = p*ln(p)-p+ln(2*pi*p)/2	(Stirling's formula - pi here
					 is the usual 3.14159...)

I didn't have the heart to expand the entire enumeration and divide by
p! to get the probability; however, by ruthlessly throwing away the less
significant terms (i.e. everything but pi(p!/p) in the enumeration, and
the last term in Stirling's formula) I came up with an approximate
probability of:

				   1
			-------------------------
			p * (p-1) * (ln(p-1) - 1)


Good luck in verifying it empirically for any given large p.....