Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

asked 5 years ago

maan gravatar image

How to find a short form of recursive defined sequences?

Hi, I'm new to sagemath.
Is there any way to so calculate/solve/find a short version of a recursive defined sequence?

E.g. I have a sequence like: (Fibonacci)

def f(n):                            
        if n == 0:  
                return 0  
        if n == 1:  
                return 1
        if n == 2:
                return 1
        else:
                return f(n-1)+f(n-2)

How can I compute a short form of fn?


In this example case fn would be:
fn=15(1+52)n15(152)n

How to find a short form of recursive defined sequences?

Hi, I'm new to sagemath.
Is there any way to so calculate/solve/find a short version of a recursive defined sequence?

E.g. I have a sequence like: (Fibonacci)

def f(n):                            
        if n == 0:  
                return 0  
        if n == 1:  
                return 1
        if n == 2:
                return 1
        else:
                return f(n-1)+f(n-2)

How can I compute a short form of fn?


In this example case fn would be:
fn=15(1+52)n15(152)n


Edit: Thanks to Emmanuel I found how to solve those equations in pdf:

from sympy import Function,rsolve  
from sympy.abc import n  
u = Function('u')  
f = u(n-1)+u(n-2)-u(n)  
rsolve(f, u(n), {u(0):0,u(1):1})  

-sqrt(5)*(1/2 - sqrt(5)/2)**n/5 + sqrt(5)*(1/2 + sqrt(5)/2)**n/5