A short investigation of the Virahanka-Fibonacci Numbers. Additional details on C-finite sequences in Sage can be found in the documentation.
Requirements: None
# Define the ring of C-finite sequences over the rationals
C.<z> = CFiniteSequences(QQ)
print(C)
The ring of C-Finite sequences in z over Rational Field
# C-finite sequences can be defined by their recurrence and initial conditions
fib = C.from_recurrence([1,1],[1,1]) # Recurrence v_{n+2} = v_{n+1} + v_n with v_0 = v_1 = 1
fib
C-finite sequence, generated by -1/(z^2 + z - 1)
# C-finite sequences can also be defined by their rational generating function
fib2 = C('1/(1-z-z^2)')
print(fib2)
print(fib==fib2)
C-finite sequence, generated by -1/(z^2 + z - 1) True
# Series truncations can be computed from the sequence
fib.series(10)
1 + x + 2*x^2 + 3*x^3 + 5*x^4 + 8*x^5 + 13*x^6 + 21*x^7 + 34*x^8 + 55*x^9 + O(x^10)
# Sequence terms can also be accessed directly
print([fib[k] for k in range(10)])
print(fib[1000])
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55] 70330367711422815821835254877183549770181269836358732742604905087154537118196933579742249494562611733487750449241765991088186363265450223647106012053374121273867339111198139373125598767690091902245245323403501
# Sage can find the closed form of the sequence (corresponding to Theorem 2.3 in the textbook)
show(fib.closed_form())
# Sage can also guess a C-recurrence from a list of initial values
C.guess([1,1,2,3,5,8])
C-finite sequence, generated by -1/(x^2 + x - 1)