Even Fibonacci Numbers

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 11 and 22, the first 1010 terms will be:

1,2,3,5,8,13,21,34,55,89,1, 2, 3, 5, 8, 13, 21, 34, 55, 89, \dots

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Solution

The Fibonacci sequence is defined by the recurrence relation:

Fn=Fn1+Fn2,F1=1,F2=2.F_n = F_{n-1} + F_{n-2}, \quad F_1 = 1, \quad F_2 = 2.

By observation, we can see that every third term is even. We can use this fact to generate the sequence and sum the even terms.

Sn=i=1nF3i,S_n = \sum_{i=1}^n F_{3i},

where nn is the number of terms to sum.

The term F3nF_{3n} is the largest term and it can not exceed the limit of 4,000,0004,000,000. We can use this fact to determine the number of terms to sum.

The Binet formula gives a closed form for the Fibonacci sequence:

Fn=ϕnψn5,F_n = \frac{\phi^n - \psi^n}{\sqrt{5}},

where ϕ=1+52\phi = \frac{1 + \sqrt{5}}{2} and ψ=152\psi = \frac{1 - \sqrt{5}}{2}.

Notice that ψn0\psi^n \to 0 as nn \to \infty. Therefore, we can approximate the number of terms to sum as:

3n<ln(4,000,0005)ln(ϕ)\begin{equation} 3n < \frac{\ln(4,000,000 \sqrt{5})}{\ln(\phi)} \end{equation}

By recursion, we note that:

Fi+3=Fi+2+Fi+1=Fi+2+Fi+2Fi=2Fi+2Fi=2(Fi+1+Fi)Fi=2Fi+1+Fi=2(Fi+Fi1)+Fi=3Fi+2Fi1=3Fi+2(FiFi2)=4Fi+Fi2Fi2=4Fi+Fi1+Fi22Fi2=4Fi+Fi1Fi2=4Fi+Fi34Fi+Fi3Fi+3=0\begin{align*} F_{i+3} &= F_{i+2} + F_{i+1} = F_{i+2} + F_{i+2} - F_{i}\\ &= 2F_{i+2} - F_{i} = 2 (F_{i+1} + F_{i}) - F_{i}\\ &= 2F_{i+1} + F_{i} = 2(F_{i} + F_{i-1}) + F_{i}\\ &= 3F_{i} + 2F_{i-1} = 3F_{i} + 2(F_{i} - F_{i-2})\\ &= 4F_{i} + F_{i} - 2F_{i-2} = 4F_{i} + F_{i-1} + F_{i-2} - 2F_{i-2}\\ &= 4F_{i} + F_{i-1} - F_{i-2}\\ &= 4F_{i} + F_{i-3}\\ \Rightarrow\quad 4F_{i} + F_{i-3} - F_{i+3} &= 0\\ \end{align*}

This gives us a recurrence relation for the even terms and using the definition of SnS_n, we sum over the recurrence relation by setting i=3ki = 3k:

4k=1nF3k+k=1nF3k3k=1nF3k+3=0,\begin{align*} 4\sum_{k=1}^n F_{3k} + \sum_{k=1}^n F_{3k-3} - \sum_{k=1}^n F_{3k+3} &= 0, \end{align*}

where the first term is simply 4Sn4S_n. In the second and third terms, we can substitute j=k1j=k-1 and j=k+1j=k+1, respectively, to get:

4Sn+j=0n1F3jj=2n+1F3j=04Sn+(F0+j=1nF3jF3n)(j=1nF3j+F3n+3F3)=04Sn+(F0+SnF3n)(Sn+F3n+3F3)=04Sn(F3n+3+F3n)+(F0+F3)=04Sn(F3n+2+F3n+1+F3n)+(F2F1+F2+F1)=04Sn2F3n+2+2F2=0.\begin{align*} 4S_n + \sum_{j=0}^{n-1} F_{3j} - \sum_{j=2}^{n+1} F_{3j} &= 0\\ 4S_n + (F_0 + \sum_{j=1}^{n} F_{3j} - F_{3n}) - (\sum_{j=1}^{n} F_{3j} + F_{3n+3} - F_{3}) &= 0\\ 4S_n + (F_0 + S_{n} - F_{3n}) - (S_{n} + F_{3n+3} - F_{3}) &= 0\\ 4S_n - (F_{3n+3}+F_{3n}) + (F_0 + F_{3}) &= 0\\ 4S_n - (F_{3n+2} + F_{3n+1} + F_{3n}) + (F_2 - F_1 + F_2 + F_1) &= 0\\ 4S_n - 2F_{3n+2} + 2F_2 &= 0. \end{align*}

Thus, we have a closed form for the sum of the even terms:

Sn=F3n+2F22.\begin{equation} S_n = \frac{F_{3n+2}-F_2}{2}. \end{equation}
import numpy as np

First, we need to find the largest term that does not exceed 4,000,0004,000,000. We can use the relation we derived in (1) to find the largest term's Fibonacci index:

index_of_largest = np.floor(
    np.log(4e6 * np.sqrt(5)) / np.log((1 + np.sqrt(5)) / 2)
).astype(int)
print(f"The largest term in our series in F_{{{index_of_largest}}}")
The largest term in our series in F_{33}
F_n = lambda n: ((1 + np.sqrt(5)) ** n - (1 - np.sqrt(5)) ** n) / (2**n * np.sqrt(5))
sum_of_evens = ((F_n(index_of_largest + 2) - F_n(2)) / 2).astype(int)
 
print(f"The sum of the even-valued terms is {sum_of_evens}")
The sum of the even-valued terms is 4613732