Академический Документы
Профессиональный Документы
Культура Документы
We want to find all the prime numbers in the natural interval [A, B], A < B, and we use the
following nave search algorithm: for each natural number X that belongs to the interval [A, B]
we verify if X is a prime number.
To verify the primality of X we use a brute force algorithm: we divide X sucessively to the
numbers 2, 3, 4,, floor(sqrt(X)) and verify that each remainder is different from zero.
We will also estimate the execution time of the program as a difference between the ending time
and the starting time of the program.
Optimizations:
only odd numbers from the [A, B] interval are tested
when testing the primality of X, only the odd potential divisors are tested
We want to compute the entropy of a binary random sequence. The algorithm has several steps:
generate a large byte list S, using the standard PRNG of the Prolog language; large means
close to 1 GB. The length of the sequence (in bytes) is given as the argument N.
compute the number of 1 bits and the number of 0 bits of the sequence S in the
variables O and Z (notice the total number of bits is T = 8*N).
compute the bit entropy of the sequence as E = - (O/T)*log2(O/T) (Z/T)*log2(Z/T)
We will also estimate the execution time of the program as a difference between the ending time
and the starting time of the program.
We will also estimate the execution time of the program as a difference between the ending time
and the starting time of the program.
Monte Carlo methods can be thought of as methods that utilize sequences of random numbers to
perform a statistical simulation. The figure below shows a sector of a circle inscribed in a square.
The ratio between the areas of these two surfaces is:
R 2
Scircle sec tor M
= 42 =
S square R 4 N
where N is the total number of random points generated inside the square, and M is number of
points that fall inside the circle sector. Using the above formula, we obtain PI 4*M/N.