[sympy] Changing function - Fibonacci

2011-08-02 Thread Hector
Hello folk, I was browsing through the code and found that fibonacci numbers are calculated by recursion method. So the time complexity is of O(n) and I don't expect space complexity be any optimal. It gave me the following results. In [1]: %timeit F_n = fibonacci(10) 10 loops, be

Re: [sympy] Changing function - Fibonacci

2011-08-02 Thread Mateusz Paprocki
Hi, On 2 August 2011 21:47, Hector wrote: > Hello folk, > > I was browsing through the code and found that fibonacci numbers are > calculated by recursion method. So the time complexity is of O(n) and I > don't expect space complexity be any optimal. It gave me the following > results. > > I

Re: [sympy] Changing function - Fibonacci

2011-08-02 Thread Fredrik Johansson
On Tue, Aug 2, 2011 at 9:47 PM, Hector wrote: > Hello folk, > > I was browsing through the code and found that fibonacci numbers are > calculated by recursion method. So the time complexity is of O(n) and I > don't expect space complexity be any optimal. It gave me the following > results. > Ther

Re: [sympy] Changing function - Fibonacci

2011-08-02 Thread Vladimir Perić
On Tue, Aug 2, 2011 at 10:08 PM, Fredrik Johansson wrote: > On Tue, Aug 2, 2011 at 9:47 PM, Hector wrote: >> Hello folk, >> >> I was browsing through the code and found that fibonacci numbers are >> calculated by recursion method. So the time complexity is of O(n) and I >> don't expect space comp

Re: [sympy] Changing function - Fibonacci

2011-08-02 Thread Hector
On Wed, Aug 3, 2011 at 1:42 AM, Vladimir Perić wrote: > On Tue, Aug 2, 2011 at 10:08 PM, Fredrik Johansson > wrote: > > On Tue, Aug 2, 2011 at 9:47 PM, Hector wrote: > >> Hello folk, > >> > >> I was browsing through the code and found that fibonacci numbers are > >> calculated by recursion metho

Re: [sympy] Changing function - Fibonacci

2011-08-02 Thread Matthew Rocklin
What's wrong with the old golden ratio trick to compute the Fibonacci sequence?. phi = (1+sqrt(S(5)))/2 def fib(n): return floor(phi**n / sqrt(5) + S.Half) map(fib, range(10)) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] On Tue, Aug 2, 2011 at 3:22 PM, Hector wrote: > > > On Wed, Aug 3, 2011 at 1:42

Re: [sympy] Changing function - Fibonacci

2011-08-02 Thread Aaron Meurer
This doesn't work, as you have to take care of precision (try computing fib(10)). I suspect that it's also slower when you do that, though Fredrik would have to comment. Also, note that we already have a GoldenRation object. Aaron Meurer On Tue, Aug 2, 2011 at 3:47 PM, Matthew Rocklin wrot

Re: [sympy] Changing function - Fibonacci

2011-08-03 Thread Fredrik Johansson
On Wed, Aug 3, 2011 at 12:06 AM, Aaron Meurer wrote: > This doesn't work, as you have to take care of precision (try > computing fib(10)).  I suspect that it's also slower when you do > that, though Fredrik would have to comment. It's a bit slower than than fast integer methods, but only real

Re: [sympy] Changing function - Fibonacci

2011-08-03 Thread Hector
On Wed, Aug 3, 2011 at 1:38 AM, Fredrik Johansson < fredrik.johans...@gmail.com> wrote: > On Tue, Aug 2, 2011 at 9:47 PM, Hector wrote: > > Hello folk, > > > > I was browsing through the code and found that fibonacci numbers are > > calculated by recursion method. So the time complexity is of O(n

Re: [sympy] Changing function - Fibonacci

2011-08-03 Thread Chris Smith
But be sure to send a python int: return sympyify(ifib(int(n))) -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegro