TITLE: Computing nth term of fibonacci-like sequence for large n
QUESTION [6 upvotes]: Sum up to nth term of fibonacci sequence for very large n can be calculated in O($\log n$) time using the following approach:
$$A = \begin{bmatrix} 1&1 \\\\1&0\end{bmatrix}^n$$ 
$$\begin{bmatrix}f(n+1) \\\\ f(n) \end{bmatrix} = A^n \begin{bmatrix}f(1) \\\\ f(0)\end{bmatrix} $$
We can calculate $A^n$ in O($\log n$) time by calculating $A$, $A^2$, $A^4$, $A^8$...
Now I have another sequence
$$
T(n) = T(n - 1) + T(n - 2) - (4n - 13)
$$
$$
T(1) = 3
$$
$$ 
T(2) = 8
$$
I want to calculate its nth term for large n in O($\log n$) time.

REPLY [4 votes]: Let $S(n) = T(n) - 4n - 25$, then
\begin{align*}
  S(n) &= T(n) - 4n - 25 \\&= T(n-1) + T(n-2) - 8n - 13 - 25
       \\&= S(n-1) + 4n - 4 + 25 + S(n-2) + 4n - 8 + 25 - 8n - 13 - 25
       \\&= S(n-1) + S(n-2)
\end{align*}
So $S(n)$ fulfills the Fibonacci recurrence. Now do as above and calculate $T(n) = S(n) + 4n+25$ afterwards.