An application of Binomial transform

In this notebook we apply the Binomial transform to the Fibonacci numbers in order to substain the main notebook where these numbers are studied in depth.


In [1]:
import sympy
from sympy import *
from sympy.abc import x, n, z, t, k
    
init_printing() # for nice printing, a-la' TeX

In [2]:
%run "sums.py"

# duplicated code, put it into "sums.py"
def expand_sum_in_eq(eq_term):
    lhs, rhs = eq_term.lhs, eq_term.rhs
    return Eq(lhs, expand_Sum(rhs))

f = IndexedBase('f')
fibs = {f[i]:fibonacci(i) for i in range(100)}

In [3]:
transforming_matrix = Matrix([
        [1,0,0,0,0,0,0,0,0],
        [0,1,0,0,0,0,0,0,0],
        [1,1,1,0,0,0,0,0,0],
        [-1,0,1,1,0,0,0,0,0],
        [1,0,0,1,1,0,0,0,0],
        [-1,0,0,0,1,1,0,0,0],
        [1,0,0,0,0,1,1,0,0],
        [-1,0,0,0,0,0,1,1,0],
        [1,0,0,0,0,0,0,1,1]])

transforming_matrix


Out[3]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & 0 & 1 & 1 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 1 & 1 & 0 & 0 & 0 & 0\\-1 & 0 & 0 & 0 & 1 & 1 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 1 & 1 & 0 & 0\\-1 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1\end{matrix}\right]$$

In [7]:
transforming_matrix**(-1)


Out[7]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 1 & -1 & 1 & 0 & 0 & 0 & 0 & 0\\-3 & -1 & 1 & -1 & 1 & 0 & 0 & 0 & 0\\4 & 1 & -1 & 1 & -1 & 1 & 0 & 0 & 0\\-5 & -1 & 1 & -1 & 1 & -1 & 1 & 0 & 0\\6 & 1 & -1 & 1 & -1 & 1 & -1 & 1 & 0\\-7 & -1 & 1 & -1 & 1 & -1 & 1 & -1 & 1\end{matrix}\right]$$

In [8]:
def gf(t): return t + 1/(1+t)

gf(t).series(n=10)


Out[8]:
$$1 + t^{2} - t^{3} + t^{4} - t^{5} + t^{6} - t^{7} + t^{8} - t^{9} + \mathcal{O}\left(t^{10}\right)$$

In [9]:
def h(t): return t*(1+2*t+t**2)/(1+t+t**2)

(gf(t)*h(t)**2).series(n=10)


Out[9]:
$$t^{2} + 2 t^{3} - t^{5} + t^{6} - t^{8} + t^{9} + \mathcal{O}\left(t^{10}\right)$$

In [7]:
pascal_matrix = Matrix([
        [1,0,0,0,0,0,0,0,0],
        [1,1,0,0,0,0,0,0,0],
        [1,2,1,0,0,0,0,0,0],
        [1,3,3,1,0,0,0,0,0],
        [1,4,6,4,1,0,0,0,0],
        [1,5,10,10,5,1,0,0,0],
        [1,6,15,20,15,6,1,0,0],
        [1,7,21,35,35,21,7,1,0],
        [1,8,28,56,70,56,28,8,1]])
pascal_matrix


Out[7]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 3 & 3 & 1 & 0 & 0 & 0 & 0 & 0\\1 & 4 & 6 & 4 & 1 & 0 & 0 & 0 & 0\\1 & 5 & 10 & 10 & 5 & 1 & 0 & 0 & 0\\1 & 6 & 15 & 20 & 15 & 6 & 1 & 0 & 0\\1 & 7 & 21 & 35 & 35 & 21 & 7 & 1 & 0\\1 & 8 & 28 & 56 & 70 & 56 & 28 & 8 & 1\end{matrix}\right]$$

In [11]:
catalan_matrix = Matrix([
        [1,0,0,0,0,0,0,0,0],
        [1,1,0,0,0,0,0,0,0],
        [2,2,1,0,0,0,0,0,0],
        [5,5,3,1,0,0,0,0,0],
        [14,14,9,4,1,0,0,0,0],
        [42,42,28,14,5,1,0,0,0],
        [132,132,90,48,20,6,1,0,0],
        [429,429,297,165,75,27,7,1,0],
        [1430,1430,1001,572,275,110,35,8,1]])
catalan_matrix


Out[11]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\5 & 5 & 3 & 1 & 0 & 0 & 0 & 0 & 0\\14 & 14 & 9 & 4 & 1 & 0 & 0 & 0 & 0\\42 & 42 & 28 & 14 & 5 & 1 & 0 & 0 & 0\\132 & 132 & 90 & 48 & 20 & 6 & 1 & 0 & 0\\429 & 429 & 297 & 165 & 75 & 27 & 7 & 1 & 0\\1430 & 1430 & 1001 & 572 & 275 & 110 & 35 & 8 & 1\end{matrix}\right]$$

In [12]:
catalan_inverse_matrix = Matrix([
        [1,0,0,0,0,0,0,0,0],
        [1,0,0,0,0,0,0,0,0],
        [0,1,0,0,0,0,0,0,0],
        [0,-1,1,0,0,0,0,0,0],
        [0,0,-2,1,0,0,0,0,0],
        [0,0,1,-3,1,0,0,0,0],
        [0,0,0,3,-4,1,0,0,0],
        [0,0,0,-1,6,-5,1,0,0],
        [0,0,0,0,-4,10,-6,1,0]])
catalan_inverse_matrix


Out[12]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & -1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 0 & -2 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 1 & -3 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 3 & -4 & 1 & 0 & 0 & 0\\0 & 0 & 0 & -1 & 6 & -5 & 1 & 0 & 0\\0 & 0 & 0 & 0 & -4 & 10 & -6 & 1 & 0\end{matrix}\right]$$

In [13]:
odd_transformed_matrix = pascal_matrix * transforming_matrix
odd_transformed_matrix


Out[13]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\3 & 6 & 4 & 1 & 0 & 0 & 0 & 0 & 0\\4 & 10 & 10 & 5 & 1 & 0 & 0 & 0 & 0\\5 & 15 & 20 & 15 & 6 & 1 & 0 & 0 & 0\\6 & 21 & 35 & 35 & 21 & 7 & 1 & 0 & 0\\7 & 28 & 56 & 70 & 56 & 28 & 8 & 1 & 0\\8 & 36 & 84 & 126 & 126 & 84 & 36 & 9 & 1\end{matrix}\right]$$

In [14]:
transforming_matrix * pascal_matrix


Out[14]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\3 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 5 & 4 & 1 & 0 & 0 & 0 & 0 & 0\\3 & 7 & 9 & 5 & 1 & 0 & 0 & 0 & 0\\1 & 9 & 16 & 14 & 6 & 1 & 0 & 0 & 0\\3 & 11 & 25 & 30 & 20 & 7 & 1 & 0 & 0\\1 & 13 & 36 & 55 & 50 & 27 & 8 & 1 & 0\\3 & 15 & 49 & 91 & 105 & 77 & 35 & 9 & 1\end{matrix}\right]$$

In [15]:
(catalan_matrix**(-1) )*odd_transformed_matrix


Out[15]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\-2 & -2 & 1 & 1 & 0 & 0 & 0 & 0 & 0\\-2 & -5 & -3 & 1 & 1 & 0 & 0 & 0 & 0\\1 & -2 & -7 & -4 & 1 & 1 & 0 & 0 & 0\\4 & 7 & -1 & -9 & -5 & 1 & 1 & 0 & 0\\3 & 12 & 15 & 1 & -11 & -6 & 1 & 1 & 0\\-2 & 3 & 21 & 26 & 4 & -13 & -7 & 1 & 1\end{matrix}\right]$$

In [16]:
catalan_inverse_matrix * odd_transformed_matrix


Out[16]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & 0 & 2 & 1 & 0 & 0 & 0 & 0 & 0\\-3 & -5 & -1 & 2 & 1 & 0 & 0 & 0 & 0\\-2 & -7 & -8 & -2 & 2 & 1 & 0 & 0 & 0\\2 & 0 & -9 & -11 & -3 & 2 & 1 & 0 & 0\\5 & 12 & 6 & -10 & -14 & -4 & 2 & 1 & 0\end{matrix}\right]$$

In [4]:
fib_matrix = Matrix([fibonacci(i) for i in range(9)])
fib_matrix_sym = Matrix([f[i] for i in range(9)])

fib_matrix, fib_matrix_sym


Out[4]:
$$\left ( \left[\begin{matrix}0\\1\\1\\2\\3\\5\\8\\13\\21\end{matrix}\right], \quad \left[\begin{matrix}f_{0}\\f_{1}\\f_{2}\\f_{3}\\f_{4}\\f_{5}\\f_{6}\\f_{7}\\f_{8}\end{matrix}\right]\right )$$

In [5]:
a = Wild('a')
std_prod = transforming_matrix * fib_matrix
sym_prod = transforming_matrix * fib_matrix_sym

std_prod, sym_prod, sym_prod.subs({f[0]:0}), sym_prod.subs({f[0]:0}).replace(f[a]+f[a+1],f[a+2])


Out[5]:
$$\left ( \left[\begin{matrix}0\\1\\2\\3\\5\\8\\13\\21\\34\end{matrix}\right], \quad \left[\begin{matrix}f_{0}\\f_{1}\\f_{0} + f_{1} + f_{2}\\- f_{0} + f_{2} + f_{3}\\f_{0} + f_{3} + f_{4}\\- f_{0} + f_{4} + f_{5}\\f_{0} + f_{5} + f_{6}\\- f_{0} + f_{6} + f_{7}\\f_{0} + f_{7} + f_{8}\end{matrix}\right], \quad \left[\begin{matrix}0\\f_{1}\\f_{1} + f_{2}\\f_{2} + f_{3}\\f_{3} + f_{4}\\f_{4} + f_{5}\\f_{5} + f_{6}\\f_{6} + f_{7}\\f_{7} + f_{8}\end{matrix}\right], \quad \left[\begin{matrix}0\\f_{1}\\f_{3}\\f_{4}\\f_{5}\\f_{6}\\f_{7}\\f_{8}\\f_{9}\end{matrix}\right]\right )$$

In [8]:
rhs=pascal_matrix * transforming_matrix * fib_matrix
rhs_sym = pascal_matrix * sym_prod
rhs, rhs_sym


Out[8]:
$$\left ( \left[\begin{matrix}0\\1\\4\\12\\33\\88\\232\\609\\1596\end{matrix}\right], \quad \left[\begin{matrix}f_{0}\\f_{0} + f_{1}\\2 f_{0} + 3 f_{1} + f_{2}\\3 f_{0} + 6 f_{1} + 4 f_{2} + f_{3}\\4 f_{0} + 10 f_{1} + 10 f_{2} + 5 f_{3} + f_{4}\\5 f_{0} + 15 f_{1} + 20 f_{2} + 15 f_{3} + 6 f_{4} + f_{5}\\6 f_{0} + 21 f_{1} + 35 f_{2} + 35 f_{3} + 21 f_{4} + 7 f_{5} + f_{6}\\7 f_{0} + 28 f_{1} + 56 f_{2} + 70 f_{3} + 56 f_{4} + 28 f_{5} + 8 f_{6} + f_{7}\\8 f_{0} + 36 f_{1} + 84 f_{2} + 126 f_{3} + 126 f_{4} + 84 f_{5} + 36 f_{6} + 9 f_{7} + f_{8}\end{matrix}\right]\right )$$

In [9]:
a_range = range(1,18,2)
lhs=Matrix([fibonacci(i) for i in a_range]) - Matrix([1 for i in range(9)])
lhs_sym=Matrix([f[i] for i in a_range]) - Matrix([1 for i in range(9)])
lhs, lhs_sym


Out[9]:
$$\left ( \left[\begin{matrix}0\\1\\4\\12\\33\\88\\232\\609\\1596\end{matrix}\right], \quad \left[\begin{matrix}f_{1} - 1\\f_{3} - 1\\f_{5} - 1\\f_{7} - 1\\f_{9} - 1\\f_{11} - 1\\f_{13} - 1\\f_{15} - 1\\f_{17} - 1\end{matrix}\right]\right )$$

In [11]:
Eq(lhs,rhs)


Out[11]:
$$\mathrm{True}$$

In [10]:
eq_sym = Eq(lhs_sym, rhs_sym)
eq_sym


Out[10]:
$$\left[\begin{matrix}f_{1} - 1\\f_{3} - 1\\f_{5} - 1\\f_{7} - 1\\f_{9} - 1\\f_{11} - 1\\f_{13} - 1\\f_{15} - 1\\f_{17} - 1\end{matrix}\right] = \left[\begin{matrix}f_{0}\\f_{0} + f_{1}\\2 f_{0} + 3 f_{1} + f_{2}\\3 f_{0} + 6 f_{1} + 4 f_{2} + f_{3}\\4 f_{0} + 10 f_{1} + 10 f_{2} + 5 f_{3} + f_{4}\\5 f_{0} + 15 f_{1} + 20 f_{2} + 15 f_{3} + 6 f_{4} + f_{5}\\6 f_{0} + 21 f_{1} + 35 f_{2} + 35 f_{3} + 21 f_{4} + 7 f_{5} + f_{6}\\7 f_{0} + 28 f_{1} + 56 f_{2} + 70 f_{3} + 56 f_{4} + 28 f_{5} + 8 f_{6} + f_{7}\\8 f_{0} + 36 f_{1} + 84 f_{2} + 126 f_{3} + 126 f_{4} + 84 f_{5} + 36 f_{6} + 9 f_{7} + f_{8}\end{matrix}\right]$$

In [18]:
f_minus1_vector = Matrix([f[-1] for i in range(9)])
one_plus_eq = eq_sym#.subs(-Integer(1),f[-1])
one_plus_eq = Eq(one_plus_eq.lhs + f_minus1_vector, one_plus_eq.rhs + f_minus1_vector)
one_plus_eq = Eq(one_plus_eq.lhs.subs(f[-1],1), one_plus_eq.rhs)
Eq(one_plus_eq.lhs, one_plus_eq.rhs.subs(fibs))


Out[18]:
$$\left[\begin{matrix}f_{1}\\f_{3}\\f_{5}\\f_{7}\\f_{9}\\f_{11}\\f_{13}\\f_{15}\\f_{17}\end{matrix}\right] = \left[\begin{matrix}f_{-1}\\f_{-1} + 1\\f_{-1} + 4\\f_{-1} + 12\\f_{-1} + 33\\f_{-1} + 88\\f_{-1} + 232\\f_{-1} + 609\\f_{-1} + 1596\end{matrix}\right]$$

In [11]:
fib0_term = f[0]
eq_sym.subs(fib0_term, fibs[fib0_term])


Out[11]:
$$\left[\begin{matrix}f_{1} - 1\\f_{3} - 1\\f_{5} - 1\\f_{7} - 1\\f_{9} - 1\\f_{11} - 1\\f_{13} - 1\\f_{15} - 1\\f_{17} - 1\end{matrix}\right] = \left[\begin{matrix}0\\f_{1}\\3 f_{1} + f_{2}\\6 f_{1} + 4 f_{2} + f_{3}\\10 f_{1} + 10 f_{2} + 5 f_{3} + f_{4}\\15 f_{1} + 20 f_{2} + 15 f_{3} + 6 f_{4} + f_{5}\\21 f_{1} + 35 f_{2} + 35 f_{3} + 21 f_{4} + 7 f_{5} + f_{6}\\28 f_{1} + 56 f_{2} + 70 f_{3} + 56 f_{4} + 28 f_{5} + 8 f_{6} + f_{7}\\36 f_{1} + 84 f_{2} + 126 f_{3} + 126 f_{4} + 84 f_{5} + 36 f_{6} + 9 f_{7} + f_{8}\end{matrix}\right]$$

Since coefficient in the triangle on the rhs are a part of Pascal triangle, namely A104712, the following is a generalization: $$ f_{2n+1} - 1 = \sum_{k=1}^{n}{{{n+1}\choose{k+1}}f_{k}} $$


In [48]:
gen_odd_fibs = Eq(f[2*n+1]-1, Sum(binomial(n+1, k+1)*f[k], (k,1,n)))
Eq(gen_odd_fibs, Sum(binomial(n+1, n-k)*f[k], (k,1,n)))


Out[48]:
$$f_{2 n + 1} - 1 = \sum_{k=1}^{n} {\binom{n + 1}{k + 1}} f_{k} = \sum_{k=1}^{n} {\binom{n + 1}{- k + n}} f_{k}$$

In [58]:
expand_sum_in_eq(gen_odd_fibs.subs(n, 8))


Out[58]:
$$f_{17} - 1 = 36 f_{1} + 84 f_{2} + 126 f_{3} + 126 f_{4} + 84 f_{5} + 36 f_{6} + 9 f_{7} + f_{8}$$

In [26]:
eq_sym.subs(fibs)


Out[26]:
$$\mathrm{True}$$

In [27]:
eq_17 = Eq(f[17],f[-1] + rhs_sym[-1])
eq_18_shift = Eq(f[n], f[n-18]+8*f[n-17]+36*f[n-16]+84*f[n-15]+126*f[n-14]+126*f[n-13]+84*f[n-12]+36*f[n-11]+9*f[n-10]+f[n-9])
eq_17, eq_18_shift


Out[27]:
$$\left ( f_{17} = f_{-1} + 8 f_{0} + 36 f_{1} + 84 f_{2} + 126 f_{3} + 126 f_{4} + 84 f_{5} + 36 f_{6} + 9 f_{7} + f_{8}, \quad f_{n} = f_{n - 18} + 8 f_{n - 17} + 36 f_{n - 16} + 84 f_{n - 15} + 126 f_{n - 14} + 126 f_{n - 13} + 84 f_{n - 12} + 36 f_{n - 11} + 9 f_{n - 10} + f_{n - 9}\right )$$

In [28]:
[eq_18_shift.subs(n,i).lhs.subs(fibs) - eq_18_shift.subs(n,i).rhs.subs(fibs) for i in range(18,32)]


Out[28]:
$$\left [ 1, \quad 1, \quad 2, \quad 3, \quad 5, \quad 8, \quad 13, \quad 21, \quad 34, \quad 55, \quad 89, \quad 144, \quad 233, \quad 377\right ]$$

again, fibonacci numbers, A000045.


In [14]:
from itertools import accumulate

to_accumulate = rhs_sym + ones(9,1)*f[-1]
even_rhs = Matrix(list(accumulate(to_accumulate, lambda folded, current_row: Add(folded, current_row) )))

even_lhs = Matrix([f[i] for i in range(2,19,2)])

even_fibs_matrix_eq = Eq(even_lhs, even_rhs)
even_fibs_matrix_eq


Out[14]:
$$\left[\begin{matrix}f_{2}\\f_{4}\\f_{6}\\f_{8}\\f_{10}\\f_{12}\\f_{14}\\f_{16}\\f_{18}\end{matrix}\right] = \left[\begin{matrix}f_{-1} + f_{0}\\2 f_{-1} + 2 f_{0} + f_{1}\\3 f_{-1} + 4 f_{0} + 4 f_{1} + f_{2}\\4 f_{-1} + 7 f_{0} + 10 f_{1} + 5 f_{2} + f_{3}\\5 f_{-1} + 11 f_{0} + 20 f_{1} + 15 f_{2} + 6 f_{3} + f_{4}\\6 f_{-1} + 16 f_{0} + 35 f_{1} + 35 f_{2} + 21 f_{3} + 7 f_{4} + f_{5}\\7 f_{-1} + 22 f_{0} + 56 f_{1} + 70 f_{2} + 56 f_{3} + 28 f_{4} + 8 f_{5} + f_{6}\\8 f_{-1} + 29 f_{0} + 84 f_{1} + 126 f_{2} + 126 f_{3} + 84 f_{4} + 36 f_{5} + 9 f_{6} + f_{7}\\9 f_{-1} + 37 f_{0} + 120 f_{1} + 210 f_{2} + 252 f_{3} + 210 f_{4} + 120 f_{5} + 45 f_{6} + 10 f_{7} + f_{8}\end{matrix}\right]$$

In [30]:
even_transformed_matrix = Matrix([
        [1,0,0,0,0,0,0,0,0],
        [2,1,0,0,0,0,0,0,0],
        [4,4,1,0,0,0,0,0,0],
        [7,10,5,1,0,0,0,0,0],
        [11,20,15,6,1,0,0,0,0],
        [16,35,35,21,7,1,0,0,0],
        [22,56,70,56,28,8,1,0,0],
        [29,84,126,126,84,36,9,1,0],
        [37,120,210,252,210,120,45,10,1]])
even_transformed_matrix


Out[30]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\4 & 4 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\7 & 10 & 5 & 1 & 0 & 0 & 0 & 0 & 0\\11 & 20 & 15 & 6 & 1 & 0 & 0 & 0 & 0\\16 & 35 & 35 & 21 & 7 & 1 & 0 & 0 & 0\\22 & 56 & 70 & 56 & 28 & 8 & 1 & 0 & 0\\29 & 84 & 126 & 126 & 84 & 36 & 9 & 1 & 0\\37 & 120 & 210 & 252 & 210 & 120 & 45 & 10 & 1\end{matrix}\right]$$

In [31]:
even_transforming_matrix = (pascal_matrix**(-1))*even_transformed_matrix
even_transforming_matrix


Out[31]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 1 & 2 & 1 & 0 & 0 & 0 & 0 & 0\\0 & 0 & 1 & 2 & 1 & 0 & 0 & 0 & 0\\0 & 0 & 0 & 1 & 2 & 1 & 0 & 0 & 0\\0 & 0 & 0 & 0 & 1 & 2 & 1 & 0 & 0\\0 & 0 & 0 & 0 & 0 & 1 & 2 & 1 & 0\\0 & 0 & 0 & 0 & 0 & 0 & 1 & 2 & 1\end{matrix}\right]$$

In [32]:
(catalan_matrix**(-1) )*even_transformed_matrix


Out[32]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\0 & 2 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\-3 & -1 & 2 & 1 & 0 & 0 & 0 & 0 & 0\\-5 & -8 & -2 & 2 & 1 & 0 & 0 & 0 & 0\\-1 & -9 & -11 & -3 & 2 & 1 & 0 & 0 & 0\\8 & 6 & -10 & -14 & -4 & 2 & 1 & 0 & 0\\12 & 27 & 16 & -10 & -17 & -5 & 2 & 1 & 0\\2 & 24 & 47 & 30 & -9 & -20 & -6 & 2 & 1\end{matrix}\right]$$

In [33]:
catalan_inverse_matrix * even_transformed_matrix


Out[33]:
$$\left[\begin{matrix}1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\2 & 3 & 1 & 0 & 0 & 0 & 0 & 0 & 0\\-1 & 2 & 3 & 1 & 0 & 0 & 0 & 0 & 0\\-6 & -6 & 1 & 3 & 1 & 0 & 0 & 0 & 0\\-7 & -15 & -10 & 0 & 3 & 1 & 0 & 0 & 0\\1 & -9 & -20 & -14 & -1 & 3 & 1 & 0 & 0\\13 & 18 & -4 & -24 & -18 & -2 & 3 & 1 & 0\end{matrix}\right]$$

In [34]:
even_transforming_matrix * fib_matrix_sym


Out[34]:
$$\left[\begin{matrix}f_{0}\\f_{0} + f_{1}\\f_{0} + 2 f_{1} + f_{2}\\f_{1} + 2 f_{2} + f_{3}\\f_{2} + 2 f_{3} + f_{4}\\f_{3} + 2 f_{4} + f_{5}\\f_{4} + 2 f_{5} + f_{6}\\f_{5} + 2 f_{6} + f_{7}\\f_{6} + 2 f_{7} + f_{8}\end{matrix}\right]$$

In [47]:
even_vector_eq_sym = Eq(even_lhs - Matrix(list(range(1,10))), 
                        pascal_matrix * even_transforming_matrix * fib_matrix_sym)
even_vector_eq_sym


Out[47]:
$$\left[\begin{matrix}f_{2} - 1\\f_{4} - 2\\f_{6} - 3\\f_{8} - 4\\f_{10} - 5\\f_{12} - 6\\f_{14} - 7\\f_{16} - 8\\f_{18} - 9\end{matrix}\right] = \left[\begin{matrix}f_{0}\\2 f_{0} + f_{1}\\4 f_{0} + 4 f_{1} + f_{2}\\7 f_{0} + 10 f_{1} + 5 f_{2} + f_{3}\\11 f_{0} + 20 f_{1} + 15 f_{2} + 6 f_{3} + f_{4}\\16 f_{0} + 35 f_{1} + 35 f_{2} + 21 f_{3} + 7 f_{4} + f_{5}\\22 f_{0} + 56 f_{1} + 70 f_{2} + 56 f_{3} + 28 f_{4} + 8 f_{5} + f_{6}\\29 f_{0} + 84 f_{1} + 126 f_{2} + 126 f_{3} + 84 f_{4} + 36 f_{5} + 9 f_{6} + f_{7}\\37 f_{0} + 120 f_{1} + 210 f_{2} + 252 f_{3} + 210 f_{4} + 120 f_{5} + 45 f_{6} + 10 f_{7} + f_{8}\end{matrix}\right]$$

In [49]:
even_vector_eq_sym.subs(fib0_term, fibs[fib0_term])


Out[49]:
$$\left[\begin{matrix}f_{2} - 1\\f_{4} - 2\\f_{6} - 3\\f_{8} - 4\\f_{10} - 5\\f_{12} - 6\\f_{14} - 7\\f_{16} - 8\\f_{18} - 9\end{matrix}\right] = \left[\begin{matrix}0\\f_{1}\\4 f_{1} + f_{2}\\10 f_{1} + 5 f_{2} + f_{3}\\20 f_{1} + 15 f_{2} + 6 f_{3} + f_{4}\\35 f_{1} + 35 f_{2} + 21 f_{3} + 7 f_{4} + f_{5}\\56 f_{1} + 70 f_{2} + 56 f_{3} + 28 f_{4} + 8 f_{5} + f_{6}\\84 f_{1} + 126 f_{2} + 126 f_{3} + 84 f_{4} + 36 f_{5} + 9 f_{6} + f_{7}\\120 f_{1} + 210 f_{2} + 252 f_{3} + 210 f_{4} + 120 f_{5} + 45 f_{6} + 10 f_{7} + f_{8}\end{matrix}\right]$$

Since coefficient in the triangle on the rhs are a part of Pascal triangle, namely A104713, the following is a generalization: $$ f_{2n} - n = \sum_{k=1}^{n-1}{{{n+1}\choose{k+2}}f_{k}} $$


In [51]:
gen_even_fibs = Eq(f[2*n]-n, Sum(binomial(n+1, k+2)*f[k], (k,1,n-1)))
Eq(gen_even_fibs, Sum(binomial(n+1, n-k-1)*f[k], (k,1,n-1)))


Out[51]:
$$- n + f_{2 n} = \sum_{k=1}^{n - 1} {\binom{n + 1}{k + 2}} f_{k} = \sum_{k=1}^{n - 1} {\binom{n + 1}{- k + n - 1}} f_{k}$$

In [57]:
expand_sum_in_eq(gen_even_fibs.subs(n, 9))


Out[57]:
$$f_{18} - 9 = 120 f_{1} + 210 f_{2} + 252 f_{3} + 210 f_{4} + 120 f_{5} + 45 f_{6} + 10 f_{7} + f_{8}$$

In [36]:
even_fibs_matrix_eq_minus1_appear = even_fibs_matrix_eq.subs(fibs)
Eq(even_fibs_matrix_eq.lhs, even_fibs_matrix_eq_minus1_appear, evaluate=False)


Out[36]:
$$\left[\begin{matrix}f_{2}\\f_{4}\\f_{6}\\f_{8}\\f_{10}\\f_{12}\\f_{14}\\f_{16}\\f_{18}\end{matrix}\right] = \left[\begin{matrix}1\\3\\8\\21\\55\\144\\377\\987\\2584\end{matrix}\right] = \left[\begin{matrix}f_{-1}\\2 f_{-1} + 1\\3 f_{-1} + 5\\4 f_{-1} + 17\\5 f_{-1} + 50\\6 f_{-1} + 138\\7 f_{-1} + 370\\8 f_{-1} + 979\\9 f_{-1} + 2575\end{matrix}\right]$$

summands on the rhs form a known sequence A054452.


In [37]:
list(accumulate([fibonacci(2*i+1)-1 for i in range(21)]))


Out[37]:
$$\left [ 0, \quad 1, \quad 5, \quad 17, \quad 50, \quad 138, \quad 370, \quad 979, \quad 2575, \quad 6755, \quad 17700, \quad 46356, \quad 121380, \quad 317797, \quad 832025, \quad 2178293, \quad 5702870, \quad 14930334, \quad 39088150, \quad 102334135, \quad 267914275\right ]$$

In [23]:
def n_gf(t): return t/(1-t)**2

n_gf(t).series(n=20)


Out[23]:
$$t + 2 t^{2} + 3 t^{3} + 4 t^{4} + 5 t^{5} + 6 t^{6} + 7 t^{7} + 8 t^{8} + 9 t^{9} + 10 t^{10} + 11 t^{11} + 12 t^{12} + 13 t^{13} + 14 t^{14} + 15 t^{15} + 16 t^{16} + 17 t^{17} + 18 t^{18} + 19 t^{19} + \mathcal{O}\left(t^{20}\right)$$

In [24]:
def odd_fib_gf(t): return t**2/((1-t)**2*(1-3*t+t**2))

odd_fib_gf(t).series(n=20)


Out[24]:
$$t^{2} + 5 t^{3} + 17 t^{4} + 50 t^{5} + 138 t^{6} + 370 t^{7} + 979 t^{8} + 2575 t^{9} + 6755 t^{10} + 17700 t^{11} + 46356 t^{12} + 121380 t^{13} + 317797 t^{14} + 832025 t^{15} + 2178293 t^{16} + 5702870 t^{17} + 14930334 t^{18} + 39088150 t^{19} + \mathcal{O}\left(t^{20}\right)$$

In [25]:
composite_odd_fibs_gf = n_gf(t)+odd_fib_gf(t)
composite_odd_fibs_gf.factor(), composite_odd_fibs_gf.series(n=20)


Out[25]:
$$\left ( \frac{t}{t^{2} - 3 t + 1}, \quad t + 3 t^{2} + 8 t^{3} + 21 t^{4} + 55 t^{5} + 144 t^{6} + 377 t^{7} + 987 t^{8} + 2584 t^{9} + 6765 t^{10} + 17711 t^{11} + 46368 t^{12} + 121393 t^{13} + 317811 t^{14} + 832040 t^{15} + 2178309 t^{16} + 5702887 t^{17} + 14930352 t^{18} + 39088169 t^{19} + \mathcal{O}\left(t^{20}\right)\right )$$

In [39]:
def odd_integers_gf(t): return ((n_gf(t)+n_gf(-t))/2).simplify()

odd_integers_gf(t).series(n=20)


Out[39]:
$$1 + 3 t^{2} + 5 t^{4} + 7 t^{6} + 9 t^{8} + 11 t^{10} + 13 t^{12} + 15 t^{14} + 17 t^{16} + 19 t^{18} + \mathcal{O}\left(t^{20}\right)$$

In [40]:
# here is the error: we should use the generating function of F(2n+1) instead of F(n) as done here!
def fib_gf(t): return t/(1-t-t**2)

fib_gf(odd_integers_gf(t)).series(n=20)


Out[40]:
$$-1 + 6 t^{2} - 35 t^{4} + 215 t^{6} - 1316 t^{8} + 8051 t^{10} - 49261 t^{12} + 301406 t^{14} - 1844167 t^{16} + 11283627 t^{18} + \mathcal{O}\left(t^{20}\right)$$

In [41]:
def even_fibs_gf(t): return n_gf(t) + fib_gf(t)/(1-t)

even_fibs_gf(t).series(n=10)


Out[41]:
$$1 + 3 t + 5 t^{2} + 8 t^{3} + 12 t^{4} + 18 t^{5} + 27 t^{6} + 41 t^{7} + 63 t^{8} + 98 t^{9} + \mathcal{O}\left(t^{10}\right)$$

In [42]:
even_fibs_matrix_eq_minus1_appear.subs(f[-1],1)


Out[42]:
$$\mathrm{True}$$

In [43]:
eq_17 = Eq(f[n], 8*f[n-17]+29*f[n-16]+84*f[n-15]+126*f[n-14]+126*f[n-13]+84*f[n-12]+36*f[n-11]+9*f[n-10]+f[n-9])
eq_17


Out[43]:
$$f_{n} = 8 f_{n - 17} + 29 f_{n - 16} + 84 f_{n - 15} + 126 f_{n - 14} + 126 f_{n - 13} + 84 f_{n - 12} + 36 f_{n - 11} + 9 f_{n - 10} + f_{n - 9}$$

In [44]:
[eq_17.subs(n,i).lhs.subs(fibs) - eq_17.subs(n,i).rhs.subs(fibs) for i in range(17,31)]


Out[44]:
$$\left [ 8, \quad 8, \quad 16, \quad 24, \quad 40, \quad 64, \quad 104, \quad 168, \quad 272, \quad 440, \quad 712, \quad 1152, \quad 1864, \quad 3016\right ]$$

which is known as A022091.



This work by <a xmlns:cc="http://creativecommons.org/ns#" href="https://github.com/massimo-nocentini/" property="cc:attributionName" rel="cc:attributionURL">Massimo Nocentini</a> is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="https://github.com/massimo-nocentini/recurrences-unfolding" rel="dct:source">https://github.com/massimo-nocentini/recurrences-unfolding</a>.