Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tribonacci series with different initial values

Tags:

algorithm

math

How to find nth tribonacci number with matrix multiplication method if the initial values are some arbitrary numbers say 1, 2 3 i.e T(1) = 1, T(2) =2 and T(3) = 3.

If T(n) = T(n-1) + T(n-2) + T(n-3) then how to find T(n) if n is very very large, I would appreciate if anyone can explain with matrix multiplication method. How to construct initial matrix.

like image 711
user650521 Avatar asked Sep 08 '12 13:09

user650521


People also ask

How many initial values do we have for a Tribonacci numbers TN?

It is also generalized to higher-order sequences includ- ing tribonacci[5], quatranacci, k-step Fibonacci sequences[1]. The 3-step Fibonacci sequence usually called the tribonacci sequence Tn is the sum of the preceding three terms having initial values 0,0,1.

Can Fibonacci series start from any number?

A generalized Fibonacci sequence can start with any two numbers and then apply the rule that subsequent terms are defined as the sum of their two predecessors. For example, if we start with 3 and 4, we get the sequence 3, 4, 7, 11, 18, 29, …

What is the Tribonacci constant?

The Tribonacci constant η is the one real root of the cubic: x3−x2−x−1=0. Its decimal expansion starts: η=1⋅83928675521416…


1 Answers

The matrix multiplication method involves using the matrix recurrence relation.

For the Fibonacci series, we can define a vector of length 2 to represent adjacent Fibonacci numbers. Using this vector, we can define a recurrence relation with a matrix multiplication:

enter image description here

Similarly, the Tribonacci series recurrence relation can be written in this way:

enter image description here

The only difference is that the vector and matrix sizes are different.

Now, to calculate a large Tribonacci number, we just apply the matrix multiplication n times, and we get:

enter image description here

The matrix to the power of n (Mn) can be efficiently calculated, because we can use an exponentiation algorithm.

Many efficient exponentiation algorithms for scalars are described by Wikipedia in Exponentiation by Squaring. We can use the same idea for matrix exponentiation.

I will describe a simple way to do this. First we write n as a binary number, eg:

n = 37 = 100101

Then, calculate M to each power of 2 by squaring the previous power of 2: M1, M2 = M1M1, M4 = M2M2, M8 = M4M4, M16 = M8M8, M32 = M16M16, ...

And finally, multiply the powers of M corresponding to the binary digits of n. In this case, Mn = M1M4M32.

After calculating that, we can multiply the matrix with the Tribonacci vector for the first 3 values, ie.

enter image description here

Because the matrices have fixed size, each matrix multiplication takes constant time. We must do O(log n) matrix multiplications. Thus, we can calculate the nth Tribonacci number in O(log n) time.

Compare this to the normal dynamic programming method, where it takes O(n) time, by calculating each Tribonacci number up to the nth Tribonacci number (ie. for (i = 3 to n) {T[i] = T[i-1]+T[i-2]+T[i-3];} return T[n];).


I will assume that you know how to code up matrix multiplication in the language of your choice.

like image 51
ronalchn Avatar answered Oct 21 '22 17:10

ronalchn