• Nem Talált Eredményt

Linear recurrence sequences (LRS)

In document Parallel Numerical Methods (Pldal 57-63)

The sequences generated by linear recurrence are among the most frequently applied ones, thanks to the ease of construction and the property that there is no need for storing huge amount of data and no need for extensive computation. As we will see later, these properties can be improved by parallelization.

Definition:

Let k be a positive integer, a0,a1,… ,ak-1,u0,u1,… ,uk-1∈ ℤ, and suppose that

un+k = ak-1·un+k-1+ ak-2·un+k-2+⋯+ a1·un+1+ a0·un

holds for n ≥ k.

Then the sequence un is called a linear recurring sequence.

k is the order of the recurrence,

u_0,u_1,...,u_k-1 are the initial values of the sequence and

a0,a2,...,ak-1 are the coefficients of the sequence.

The vector is called the nth state vector of the sequence.

The matrix

is the so called companion matrix.

Lemma:

Let un be a linear recurrence sequence, is its state vector and M(u) is the corresponding companion matrix. Then

. Proof:

By the definition of companion matrix

Hence we get

which can be proven for general n by a simple induction. √ Example:

Let k=2, a0 = a1 = 1, u0 = 0 and u1 = 1.

The seuence defined by these arguments are called Fibonacci sequence.

The first few members of the sequence are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...

Definition:

Let m be a positive integer, such that m > 1.

The sequence xn = un mod m is called the reduced sequence of un modulo m.

Example:

Let k=2, a0 = a1 = 1, u0 = 0, u1 = 1 and m = 2.

The first few members of the sequence xn = un mod 2 are 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, ...

We may observe that the different members are repeated systematically.

Definition:

The sequence un is called periodic, if ∃ p,p0 integers, such that 0<p and un = un+p, ∀ n ≥ p0.

Random number generators

p is called the period length, while p0 is called the length of the preperiod of the sequence.

If p0=0, then the sequence is called purely periodic.

Theorem:

Let un be a linear recurrence sequence, 1<m is an integer and xn is the reduced sequence of un modulo m.

Proof:

Since the members of xn are from a finite set, thus the vector (xn,xn+1,…,xn+k-1) created from the consecutive elements of it, can take only a finitely many different values. A suitable long sequence contains two indices i<j, such that

(xi,xi+1,…,xi+k-1) = (xj,xj+1,…,xj+k-1).

Then by the generating recurrence relation (xi+1,xi+2,…,xi+k) = (xj+1,xj+2,…,xj+k) .

Iteratively applying this rule, we get xi+m = xj+m, for all 0 ≤ m. This exactly means that the sequence is periodic. √ Definition:

Let xn be a periodic sequence mod m, p be the period length while p0 is the length of its preperiod. We say that xn is uniformly distributed, if every residue appears in the same number in one period.

More formally: let

R(s,a)= Card {i ∣ a = xi,s ≤ i < s+p}.

We say that xn is uniformly distributed, if

and ∀ 0 ≤ a<m.

Example:

We saw that the Fibonacci sequence is purely periodic modulo 2 and it has period length 3. We may observe further that it is not uniformly distributed.

Remark:

General conditions on uniform distribution for linear recurrence sequences can be found in [6], [7], [1] and [2].

The period length of a linear recurrence sequence is closely related to the order of its recurrence relation. If we would like to have a sequence with better properties, we should try to find higher order recurrences. By the

3. M[i]← A[i]·U[i] mod m 4. endpfor

5.

6. pfor i← 1,…,k-1 do 7. A[i-1]← A[i]

8. endpfor 9. A[k-1]← m 10. return (m) 11. endwhile

The behaviour of the algorithm is corresponding to the following picture:

Linear recurring sequence with shift register

Once we have started the algorithm, it keeps producing random numbers consequtively, until we terminate. In line 10. the algorithm sends the random numbers to the output, in the form of a data stream. But then, the time complexity of the algorithm cannot be defined in the usual way. We may observe, however, how long it takes to produce a single random number. By the properties of the applied parallel cycles, one can see that the number of steps do not depend on the size of the input, except one line. This particular line is the 5. Here we have to compute a sum of many members, which requires O(log(k)) operations, by the previous chapters. The summation can be solved by the following architecture:

Parallel adder for linear recurrence sequences

The number of necessary processors are k, because of the amount of the multiplications. (For the additions, one needs only processors.)

Rearranging the operations and storing some particular intermediate results, we may reduce the time complextiy corresponding to the generation for a single random number, without increasing the number of processors.

For this, we need the following

Random number generators

Theorem:

Let u be linear recurring sequence, defined by the recurrence un+k=ak-1un+k-1+⋯+a0un (1)

and let us define the sequence of vectors v by:

v0n=a0un-1

Substitute n-k to n in (1). Then we get un=ak-1un-1+⋯+a0un-k. (4)

By definition, the right-hand side of the equation is vk-1n, which proves (2).

Let fix i.

Substitute the definition of vi-1n to (3). Then we arrive exactly to the definition of vin and thus (3) is proven. √ By the theorem we can construct the following algorithm:

Modified Linear Recurring Sequence

The lines 1-3. are some initial stepsthat should be executed only once during the run of the algorithm. The time complexity of lines 5-8. are constant, thus the time of the generation of a random number does not depend on the order of the recurrence. The number of necessary processors are still k.

The data flow graph of the algorithm is the following:

Parallel linear recurrence sequence

References

[1] Galántai Aurél: Alkalmazott lineáris algebra;1996Miskolci Egyetemi Kiadó.

[2] Ivanyos Gábor - Szabó Réka - Rónyai Lajos: Algoritmusok;Typotex.

[3] David David E. Keyes: Parallel Numerical Algorithms: An Introduction;1977Springer.

[4] Rudolf Lidl and Harald Niederreiter: Introduction to Finite Fields and Their Applications;1994Cambridge University Press.

[5] László Lovász: Complexity of Algorithms;Lecture notes, ELTE.

[6] Harald Niederreiter: Quasi-Monte Carlo Methods;2010John Wiley & Sons, Ltd.

In document Parallel Numerical Methods (Pldal 57-63)