Computer Scientist

Tuesday, 12 June 2012

How to estimate the order of magnitude of Factorial product

The Factorial of a number usually denotes a very big order of magnitude, especially for the computer world. In order to approximate the magnitude of the factorial of a number, it is necessary to find a method to represent the factorial of a number and to keep it into the computer memory. In my example, I am estimating the factorial of 200 which exceeds much more than the capability of any type of C programming language to keep it. An uniform method to represent this big number is important during the estimation. The only way to represent this gigantic big number is by using some smaller numbers that are with in the capability of a C compiler.

My method to represent a number is to use the prime numbers that is smaller that this number. The big number can be factorised into these prime number, so the big number can easily represented the some powers of these prime numbers. For example:

10! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10
      = 1 x 2 x 3 x ( 2 x 2 ) x 5 x ( 2 x 3 ) x 7 x ( 2 x 2 x 2 ) x ( 3 x 3 ) x ( 2 x 5 )
      = 28 x 34 x 52 x 7

In this case, the factorial of 10 can be represented by these four much smaller prime numbers: 2, 3, 5, 7 with their exponential numbers. Although it is difficult to reproduce the similar procedure for the factorial of 200 by sketching on the paper, the result of the factorial of 200 is not difficult to estimate, because the only difference of the factorial of 200 and that of 10 is the number of prime numbers involved. According to the prime number list referring to the wikipedia page, there are only 47 prime numbers smaller than 200. The factorial of 200 is easily represented by these prime numbers with their exponential numbers. The problem of finding all of the prime numbers smaller than a number is out of discussion of this thread. I will discuss it in more details in another thread.

When we've got the prime-numbers representation of the factorial number, the next task should be concerned is how to estimate its magnitude using this prime_number representation.

As the scientific representation is used to represent a big number, what we concern is the number zeros following the number if the first radix point is placed immediately after the first significant digit, for example, 1.23456 x 1020. The magnitude of this number is ten raised to power of 20. In other words, we are counting the number of zeros when we are talking about the magnitude of a number. The example mentioned above is for decimal number. As for the binary number, zero should still be the digit to be counted, but with different means.

I will give the method for decimal number magnitude estimation, firstly. In order to count the number zero which means a ten (10), we need to make a logarithm to the original number. Using the prime-number representation will make a more convenient way to calculate.

log10(10!) = log10(28 x 34 x 52 x 7)
                  = log(28) + log10(34) + log10(52) + log10(7)
                  = 8 x log10(2) + 4 x log10(3) + 2 x log10(5) + log10(7)

These much smaller prime-numbers logarithm is easily to be calculated. Then the number of zeros ( x 10) can be evaluated form this method.

As for a binary number the log2() should be used to calculate the number twos.

No comments:

Post a Comment